|
@@ -27,64 +27,64 @@ public class GlobalExceptionHandler {
|
|
* @param e 异常
|
|
* @param e 异常
|
|
* @return 统一返回结果
|
|
* @return 统一返回结果
|
|
*/
|
|
*/
|
|
- @ExceptionHandler(Exception.class)
|
|
|
|
- @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
|
|
|
- public WVPResult<String> exceptionHandler(Exception e) {
|
|
|
|
- logger.error("[全局异常]: ", e);
|
|
|
|
- return WVPResult.fail(ErrorCode.ERROR500.getCode(), e.getMessage());
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 默认异常处理
|
|
|
|
- * @param e 异常
|
|
|
|
- * @return 统一返回结果
|
|
|
|
- */
|
|
|
|
- @ExceptionHandler(IllegalStateException.class)
|
|
|
|
- @ResponseStatus(HttpStatus.BAD_REQUEST)
|
|
|
|
- public WVPResult<String> exceptionHandler(IllegalStateException e) {
|
|
|
|
- logger.error("[400异常]: 400", e);
|
|
|
|
- return WVPResult.fail(ErrorCode.ERROR400);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 自定义异常处理, 处理controller中返回的错误
|
|
|
|
- * @param e 异常
|
|
|
|
- * @return 统一返回结果
|
|
|
|
- */
|
|
|
|
- @ExceptionHandler(ControllerException.class)
|
|
|
|
- @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
|
|
|
- public ResponseEntity<WVPResult<String>> exceptionHandler(ControllerException e) {
|
|
|
|
- return new ResponseEntity<>(WVPResult.fail(e.getCode(), e.getMsg()), HttpStatus.OK);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 登陆失败
|
|
|
|
- *
|
|
|
|
- * @param e 异常
|
|
|
|
- * @return 统一返回结果
|
|
|
|
- */
|
|
|
|
- @ExceptionHandler(BadCredentialsException.class)
|
|
|
|
- @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
|
|
|
- public ResponseEntity<WVPResult<String>> exceptionHandler(BadCredentialsException e) {
|
|
|
|
- return new ResponseEntity<>(WVPResult.fail(ErrorCode.ERROR100.getCode(), e.getMessage()), HttpStatus.OK);
|
|
|
|
- }
|
|
|
|
|
|
+// @ExceptionHandler(Exception.class)
|
|
|
|
+// @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
|
|
|
+// public WVPResult<String> exceptionHandler(Exception e) {
|
|
|
|
+// logger.error("[全局异常]: ", e);
|
|
|
|
+// return WVPResult.fail(ErrorCode.ERROR500.getCode(), e.getMessage());
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+// /**
|
|
|
|
+// * 默认异常处理
|
|
|
|
+// * @param e 异常
|
|
|
|
+// * @return 统一返回结果
|
|
|
|
+// */
|
|
|
|
+// @ExceptionHandler(IllegalStateException.class)
|
|
|
|
+// @ResponseStatus(HttpStatus.BAD_REQUEST)
|
|
|
|
+// public WVPResult<String> exceptionHandler(IllegalStateException e) {
|
|
|
|
+// logger.error("[400异常]: 400", e);
|
|
|
|
+// return WVPResult.fail(ErrorCode.ERROR400);
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+//
|
|
|
|
+// /**
|
|
|
|
+// * 自定义异常处理, 处理controller中返回的错误
|
|
|
|
+// * @param e 异常
|
|
|
|
+// * @return 统一返回结果
|
|
|
|
+// */
|
|
|
|
+// @ExceptionHandler(ControllerException.class)
|
|
|
|
+// @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
|
|
|
+// public ResponseEntity<WVPResult<String>> exceptionHandler(ControllerException e) {
|
|
|
|
+// return new ResponseEntity<>(WVPResult.fail(e.getCode(), e.getMsg()), HttpStatus.OK);
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// /**
|
|
|
|
+// * 登陆失败
|
|
|
|
+// *
|
|
|
|
+// * @param e 异常
|
|
|
|
+// * @return 统一返回结果
|
|
|
|
+// */
|
|
|
|
+// @ExceptionHandler(BadCredentialsException.class)
|
|
|
|
+// @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
|
|
|
+// public ResponseEntity<WVPResult<String>> exceptionHandler(BadCredentialsException e) {
|
|
|
|
+// return new ResponseEntity<>(WVPResult.fail(ErrorCode.ERROR100.getCode(), e.getMessage()), HttpStatus.OK);
|
|
|
|
+// }
|
|
|
|
|
|
/**
|
|
/**
|
|
* 全局异常处理
|
|
* 全局异常处理
|
|
*/
|
|
*/
|
|
- @RestControllerAdvice
|
|
|
|
- public static class AuthException {
|
|
|
|
|
|
+// @RestControllerAdvice
|
|
|
|
+// public static class AuthException {
|
|
|
|
|
|
- private Logger logger = LoggerFactory.getLogger(AuthException.class);
|
|
|
|
|
|
+// private Logger logger = LoggerFactory.getLogger(AuthException.class);
|
|
|
|
|
|
- // 拦截:未登录异常
|
|
|
|
- @ExceptionHandler(NotLoginException.class)
|
|
|
|
- public ResponseEntity<WVPResult> handlerException(NotLoginException e) {
|
|
|
|
- logger.warn("[未登录异常]: {}", e.getMessage());
|
|
|
|
- // 打印堆栈,以供调试
|
|
|
|
|
|
+ // 拦截:未登录异常
|
|
|
|
+ @ExceptionHandler(NotLoginException.class)
|
|
|
|
+ public ResponseEntity<WVPResult> handlerException(NotLoginException e) {
|
|
|
|
+ logger.warn("[未登录异常]: {}", e.getMessage());
|
|
|
|
+ // 打印堆栈,以供调试
|
|
// e.printStackTrace();
|
|
// e.printStackTrace();
|
|
- // 构造包含401状态码和对应数据的WVPResult对象
|
|
|
|
|
|
+ // 构造包含401状态码和对应数据的WVPResult对象
|
|
WVPResult result = WVPResult.fail(ErrorCode.ERROR401);
|
|
WVPResult result = WVPResult.fail(ErrorCode.ERROR401);
|
|
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(result);
|
|
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(result);
|
|
}
|
|
}
|
|
@@ -150,5 +150,5 @@ public class GlobalExceptionHandler {
|
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(result);
|
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(result);
|
|
|
|
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
+// }
|
|
}
|
|
}
|