deason 5 年之前
父節點
當前提交
430a1a0f05

+ 0 - 36
src/main/java/cn/com/qmth/examcloud/app/core/aspect/RestControllerAspect.java

@@ -1,36 +0,0 @@
-/*
- * *************************************************
- * Copyright (c) 2018 QMTH. All Rights Reserved.
- * Created by Deason on 2018-07-16 15:17:21.
- * *************************************************
- */
-
-package cn.com.qmth.examcloud.app.core.aspect;
-
-import cn.com.qmth.examcloud.app.model.Result;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.web.bind.annotation.ExceptionHandler;
-import org.springframework.web.bind.annotation.ResponseBody;
-import org.springframework.web.bind.annotation.RestController;
-import org.springframework.web.bind.annotation.RestControllerAdvice;
-
-@RestControllerAdvice(annotations = RestController.class)
-public class RestControllerAspect {
-    private final static Logger log = LoggerFactory.getLogger(RestControllerAspect.class);
-
-    @ResponseBody
-    @ExceptionHandler(value = RuntimeException.class)
-    public Result handle(RuntimeException e) {
-        log.error(e.getMessage(), e);
-        return new Result().error(e.getMessage());
-    }
-
-    @ResponseBody
-    @ExceptionHandler(value = Exception.class)
-    public Result handle(Exception e) {
-        log.error(e.getMessage(), e);
-        return new Result().error(e.getMessage());
-    }
-
-}

+ 14 - 12
src/main/java/cn/com/qmth/examcloud/app/core/aspect/ControllerAspect.java → src/main/java/cn/com/qmth/examcloud/app/core/config/ControllerAdviceHandler.java

@@ -1,23 +1,18 @@
-/*
- * *************************************************
- * Copyright (c) 2018 QMTH. All Rights Reserved.
- * Created by Deason on 2018-07-16 15:59:42.
- * *************************************************
- */
-
-package cn.com.qmth.examcloud.app.core.aspect;
+package cn.com.qmth.examcloud.app.core.config;
 
 import cn.com.qmth.examcloud.app.model.Result;
+import cn.com.qmth.examcloud.commons.exception.StatusException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.ControllerAdvice;
 import org.springframework.web.bind.annotation.ExceptionHandler;
 import org.springframework.web.bind.annotation.ResponseBody;
 
-@ControllerAdvice(annotations = Controller.class)
-public class ControllerAspect {
-    private final static Logger log = LoggerFactory.getLogger(ControllerAspect.class);
+@ResponseBody
+@ControllerAdvice
+public class ControllerAdviceHandler {
+
+    private final static Logger log = LoggerFactory.getLogger(ControllerAdviceHandler.class);
 
     @ResponseBody
     @ExceptionHandler(value = RuntimeException.class)
@@ -33,4 +28,11 @@ public class ControllerAspect {
         return new Result().error(e.getMessage());
     }
 
+    @ResponseBody
+    @ExceptionHandler(value = StatusException.class)
+    public Result handle(StatusException e) {
+        log.error(e.getMessage(), e);
+        return new Result().error(e.getMessage());
+    }
+
 }