|
@@ -16,23 +16,12 @@ public class ControllerExceptionHandler {
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(ControllerExceptionHandler.class.getSimpleName());
|
|
private static final Logger logger = LoggerFactory.getLogger(ControllerExceptionHandler.class.getSimpleName());
|
|
|
|
|
|
- /**
|
|
|
|
- * 未知的运行时异常
|
|
|
|
- */
|
|
|
|
- @ExceptionHandler(RuntimeException.class)
|
|
|
|
- @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
|
|
|
- @ResponseBody
|
|
|
|
- public BaseResp serverError(RuntimeException ex) {
|
|
|
|
- logger.warn("server error: ", ex);
|
|
|
|
- return BaseResp.error(ex);
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* 没有权限
|
|
* 没有权限
|
|
*
|
|
*
|
|
* @return 没权限
|
|
* @return 没权限
|
|
*/
|
|
*/
|
|
|
|
+ @ResponseBody
|
|
@ExceptionHandler(ForbiddenException.class)
|
|
@ExceptionHandler(ForbiddenException.class)
|
|
@ResponseStatus(HttpStatus.FORBIDDEN)
|
|
@ResponseStatus(HttpStatus.FORBIDDEN)
|
|
public BaseResp forbiddenError(ForbiddenException ex) {
|
|
public BaseResp forbiddenError(ForbiddenException ex) {
|
|
@@ -40,12 +29,14 @@ public class ControllerExceptionHandler {
|
|
return BaseResp.error(ex);
|
|
return BaseResp.error(ex);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 用户没有登录
|
|
* 用户没有登录
|
|
*
|
|
*
|
|
* @param ex 错误
|
|
* @param ex 错误
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
|
|
+ @ResponseBody
|
|
@ExceptionHandler(UnauthorizedException.class)
|
|
@ExceptionHandler(UnauthorizedException.class)
|
|
@ResponseStatus(HttpStatus.UNAUTHORIZED)
|
|
@ResponseStatus(HttpStatus.UNAUTHORIZED)
|
|
public BaseResp unauthorizedError(UnauthorizedException ex) {
|
|
public BaseResp unauthorizedError(UnauthorizedException ex) {
|
|
@@ -53,4 +44,19 @@ public class ControllerExceptionHandler {
|
|
return BaseResp.error(ex);
|
|
return BaseResp.error(ex);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 未知的运行时异常
|
|
|
|
+ */
|
|
|
|
+ @ResponseBody
|
|
|
|
+ @ExceptionHandler(RuntimeException.class)
|
|
|
|
+ @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
|
|
|
+ public BaseResp serverError(RuntimeException ex) {
|
|
|
|
+ logger.warn("server error: ", ex);
|
|
|
|
+ return BaseResp.error(ex);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|