Sfoglia il codice sorgente

修复全局错误异常

tuonina 5 anni fa
parent
commit
c45ab3a4e9

+ 18 - 12
tuon-core/src/main/java/cn/tonyandmoney/tuon/core/error/ControllerExceptionHandler.java

@@ -16,23 +16,12 @@ public class ControllerExceptionHandler {
 
     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 没权限
      */
+    @ResponseBody
     @ExceptionHandler(ForbiddenException.class)
     @ResponseStatus(HttpStatus.FORBIDDEN)
     public BaseResp forbiddenError(ForbiddenException ex) {
@@ -40,12 +29,14 @@ public class ControllerExceptionHandler {
         return BaseResp.error(ex);
     }
 
+
     /**
      * 用户没有登录
      *
      * @param ex 错误
      * @return
      */
+    @ResponseBody
     @ExceptionHandler(UnauthorizedException.class)
     @ResponseStatus(HttpStatus.UNAUTHORIZED)
     public BaseResp unauthorizedError(UnauthorizedException ex) {
@@ -53,4 +44,19 @@ public class ControllerExceptionHandler {
         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);
+
+    }
+
+
+
 }