Skip to content

Commit

Permalink
REQUEST_TIMEOUT
Browse files Browse the repository at this point in the history
  • Loading branch information
JiakunXu committed Aug 3, 2023
1 parent 28c36c2 commit 08fcd03
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public class Constants {

public static final int PROXY_AUTHENTICATION_REQUIRED = 407;

public static final int REQUEST_TIMEOUT = 408;

public static final int INTERNAL_SERVER_ERROR = 500;

public static final int NOT_IMPLEMENTED = 501;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,21 @@
import org.springframework.security.core.AuthenticationException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.context.request.async.AsyncRequestTimeoutException;

/**
* @author JiakunXu
*/
@RestControllerAdvice
public class BaseExceptionHandler {

@ExceptionHandler(value = AccessDeniedException.class)
public ExceptionResponse exceptionHandler(AccessDeniedException e) {
ExceptionResponse response = new ExceptionResponse(Constants.FORBIDDEN, "没有权限,请联系管理员授权");

return response;
}

@ExceptionHandler(value = AuthenticationException.class)
public ExceptionResponse exceptionHandler(AuthenticationException e) {
ExceptionResponse response = new ExceptionResponse(Constants.INTERNAL_SERVER_ERROR,
Expand All @@ -23,9 +31,10 @@ public ExceptionResponse exceptionHandler(AuthenticationException e) {
return response;
}

@ExceptionHandler(value = AccessDeniedException.class)
public ExceptionResponse exceptionHandler(AccessDeniedException e) {
ExceptionResponse response = new ExceptionResponse(Constants.FORBIDDEN, "没有权限,请联系管理员授权");
@ExceptionHandler(value = AsyncRequestTimeoutException.class)
public ExceptionResponse exceptionHandler(AsyncRequestTimeoutException e) {
ExceptionResponse response = new ExceptionResponse(Constants.REQUEST_TIMEOUT,
e.getMessage());

return response;
}
Expand All @@ -47,7 +56,8 @@ public ExceptionResponse exceptionHandler(SystemException e) {
@ExceptionHandler(value = Exception.class)
public ExceptionResponse exceptionHandler(Exception e) {
ExceptionResponse response = new ExceptionResponse(Constants.SERVICE_UNAVAILABLE,
e == null ? "系统错误" : e.getCause().getMessage());
e == null ? "系统错误"
: (e.getCause() == null ? e.getMessage() : e.getCause().getMessage()));

return response;
}
Expand Down

0 comments on commit 08fcd03

Please sign in to comment.