|
@@ -0,0 +1,49 @@
|
|
|
+/*
|
|
|
+ * *************************************************
|
|
|
+ * Copyright (c) 2018 QMTH. All Rights Reserved.
|
|
|
+ * Created by Deason on 2018-10-25 13:52:55.
|
|
|
+ * *************************************************
|
|
|
+ */
|
|
|
+
|
|
|
+package cn.com.qmth.examcloud.core.print.common.aspect;
|
|
|
+
|
|
|
+import cn.com.qmth.examcloud.commons.base.exception.StatusException;
|
|
|
+import cn.com.qmth.examcloud.core.print.common.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;
|
|
|
+
|
|
|
+import static cn.com.qmth.examcloud.core.print.common.Result.error;
|
|
|
+
|
|
|
+@RestControllerAdvice(annotations = RestController.class)
|
|
|
+public class AspectRestController {
|
|
|
+ private final static Logger log = LoggerFactory.getLogger(AspectRestController.class);
|
|
|
+
|
|
|
+ @ResponseBody
|
|
|
+ @ExceptionHandler(value = RuntimeException.class)
|
|
|
+ public Result handle(RuntimeException e) {
|
|
|
+ if (e instanceof StatusException) {
|
|
|
+ StatusException se = (StatusException) e;
|
|
|
+ log.error(se.toJson());
|
|
|
+ return new Result(se.getCode(), se.getDesc());
|
|
|
+ }
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
+ return error(e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ @ResponseBody
|
|
|
+ @ExceptionHandler(value = Exception.class)
|
|
|
+ public Result handle(Exception e) {
|
|
|
+ if (e instanceof StatusException) {
|
|
|
+ StatusException se = (StatusException) e;
|
|
|
+ log.error(se.toJson());
|
|
|
+ return new Result(se.getCode(), se.getDesc());
|
|
|
+ }
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
+ return error(e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+}
|