1
|
1
|
package org.thingsboard.server.config.yunteng;
|
|
2
|
+
|
2
|
3
|
import lombok.RequiredArgsConstructor;
|
3
|
4
|
import org.springframework.http.HttpStatus;
|
4
|
5
|
import org.springframework.security.access.AccessDeniedException;
|
|
6
|
+import org.springframework.security.authentication.AccountExpiredException;
|
5
|
7
|
import org.springframework.web.bind.MethodArgumentNotValidException;
|
6
|
8
|
import org.springframework.web.bind.annotation.ControllerAdvice;
|
7
|
9
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
...
|
...
|
@@ -12,6 +14,7 @@ import org.thingsboard.server.exception.yunteng.YunTengErrorResponseHandler; |
12
|
14
|
import javax.servlet.http.HttpServletRequest;
|
13
|
15
|
import javax.servlet.http.HttpServletResponse;
|
14
|
16
|
import java.util.Objects;
|
|
17
|
+
|
15
|
18
|
@ControllerAdvice(basePackages = "org.thingsboard.server.controller.yunteng")
|
16
|
19
|
@RequiredArgsConstructor
|
17
|
20
|
public class ControllerExceptionHandler {
|
...
|
...
|
@@ -20,65 +23,58 @@ public class ControllerExceptionHandler { |
20
|
23
|
|
21
|
24
|
@ExceptionHandler(YunTengException.class)
|
22
|
25
|
public void handleYunTengException(YunTengException ex, HttpServletResponse response) {
|
23
|
|
- response.setCharacterEncoding("utf-8");
|
24
|
26
|
errorResponseHandler.handle(ex, response);
|
25
|
27
|
}
|
26
|
28
|
|
27
|
29
|
@ExceptionHandler(MethodArgumentNotValidException.class)
|
28
|
30
|
public void handleMethodArgumentNotValidException(
|
29
|
|
- MethodArgumentNotValidException ex, HttpServletResponse response) {
|
30
|
|
- response.setCharacterEncoding("utf-8");
|
|
31
|
+ MethodArgumentNotValidException ex, HttpServletResponse response) {
|
31
|
32
|
errorResponseHandler.handle(
|
32
|
|
- new YunTengException(
|
33
|
|
- ErrorMessage.INVALID_PARAMETER.setMessage(
|
34
|
|
- Objects.requireNonNull(ex.getBindingResult().getFieldError()).getDefaultMessage()),
|
35
|
|
- HttpStatus.BAD_REQUEST),
|
36
|
|
- response);
|
|
33
|
+ new YunTengException(
|
|
34
|
+ ErrorMessage.INVALID_PARAMETER.setMessage(
|
|
35
|
+ Objects.requireNonNull(ex.getBindingResult().getFieldError()).getDefaultMessage()),
|
|
36
|
+ HttpStatus.BAD_REQUEST),
|
|
37
|
+ response);
|
37
|
38
|
}
|
38
|
39
|
|
39
|
40
|
@ExceptionHandler(YtDataValidationException.class)
|
40
|
41
|
public void handleDataValidationException(
|
41
|
|
- YtDataValidationException ex, HttpServletRequest request, HttpServletResponse response) {
|
42
|
|
- response.setCharacterEncoding("utf-8");
|
|
42
|
+ YtDataValidationException ex, HttpServletRequest request, HttpServletResponse response) {
|
43
|
43
|
YunTengException YunTengException =
|
44
|
|
- new YunTengException(
|
45
|
|
- ErrorMessage.BAD_PARAMETER.setMessage(ex.getMessage()), HttpStatus.BAD_REQUEST);
|
|
44
|
+ new YunTengException(
|
|
45
|
+ ErrorMessage.BAD_PARAMETER.setMessage(ex.getMessage()), HttpStatus.BAD_REQUEST);
|
46
|
46
|
errorResponseHandler.handle(YunTengException, response);
|
47
|
47
|
}
|
48
|
48
|
|
49
|
49
|
@ExceptionHandler(TooManyRequestException.class)
|
50
|
50
|
public void handleTooManyRequestException(HttpServletResponse response) {
|
51
|
|
- response.setCharacterEncoding("utf-8");
|
52
|
51
|
errorResponseHandler.handle(
|
53
|
|
- new YunTengException(ErrorMessage.TOO_MANY_REQUEST, HttpStatus.TOO_MANY_REQUESTS),
|
54
|
|
- response);
|
|
52
|
+ new YunTengException(ErrorMessage.TOO_MANY_REQUEST, HttpStatus.TOO_MANY_REQUESTS),
|
|
53
|
+ response);
|
55
|
54
|
}
|
56
|
55
|
|
57
|
56
|
@ExceptionHandler(AccessDeniedException.class)
|
58
|
57
|
public void handleAccessDeniedException(AccessDeniedException ex, HttpServletResponse response) {
|
59
|
|
- response.setCharacterEncoding("utf-8");
|
60
|
58
|
errorResponseHandler.handle(
|
61
|
|
- new YunTengException(
|
62
|
|
- ErrorMessage.ACCESS_DENIED.setMessage(ex.getMessage()), HttpStatus.FORBIDDEN),
|
63
|
|
- response);
|
|
59
|
+ new YunTengException(
|
|
60
|
+ ErrorMessage.ACCESS_DENIED.setMessage(ex.getMessage()), HttpStatus.FORBIDDEN),
|
|
61
|
+ response);
|
64
|
62
|
}
|
65
|
63
|
|
66
|
64
|
@ExceptionHandler(NoneTenantAssetException.class)
|
67
|
65
|
public void handleNoneTenantAssetException(
|
68
|
|
- NoneTenantAssetException ex, HttpServletResponse response) {
|
69
|
|
- response.setCharacterEncoding("utf-8");
|
|
66
|
+ NoneTenantAssetException ex, HttpServletResponse response) {
|
70
|
67
|
errorResponseHandler.handle(
|
71
|
|
- new YunTengException(
|
72
|
|
- ErrorMessage.NONE_TENANT_ASSET.setMessage(ex.getMessage()), HttpStatus.NOT_FOUND),
|
73
|
|
- response);
|
|
68
|
+ new YunTengException(
|
|
69
|
+ ErrorMessage.NONE_TENANT_ASSET.setMessage(ex.getMessage()), HttpStatus.NOT_FOUND),
|
|
70
|
+ response);
|
74
|
71
|
}
|
75
|
72
|
|
76
|
73
|
@ExceptionHandler(EntityCreationException.class)
|
77
|
|
- public void handleEntityCreationException(
|
78
|
|
- EntityCreationException ex, HttpServletResponse response) {
|
79
|
|
- response.setCharacterEncoding("utf-8");
|
|
74
|
+ public void handleEntityCreationException(HttpServletResponse response) {
|
80
|
75
|
errorResponseHandler.handle(
|
81
|
|
- new YunTengException(ErrorMessage.SEND_DESTINATION_NOT_FOUND, HttpStatus.PRECONDITION_FAILED),
|
82
|
|
- response);
|
|
76
|
+ new YunTengException(
|
|
77
|
+ ErrorMessage.SEND_DESTINATION_NOT_FOUND, HttpStatus.PRECONDITION_FAILED),
|
|
78
|
+ response);
|
83
|
79
|
}
|
84
|
80
|
} |
...
|
...
|
|