|
@@ -0,0 +1,30 @@
|
|
|
+package com.diagbot.exception;
|
|
|
+
|
|
|
+import com.diagbot.dto.RespDTO;
|
|
|
+import org.springframework.http.HttpStatus;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
+import org.springframework.web.bind.annotation.ControllerAdvice;
|
|
|
+import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
|
+import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Description: 错误通用处理
|
|
|
+ * @author: gaodm
|
|
|
+ * @time: 2018/8/2 14:22
|
|
|
+ */
|
|
|
+@ControllerAdvice
|
|
|
+@ResponseBody
|
|
|
+public class CommonExceptionHandler {
|
|
|
+
|
|
|
+ @ExceptionHandler(CommonException.class)
|
|
|
+ public ResponseEntity<RespDTO> handleException(Exception e) {
|
|
|
+ RespDTO resp = new RespDTO();
|
|
|
+ CommonException taiChiException = (CommonException) e;
|
|
|
+ resp.code = taiChiException.getCode();
|
|
|
+ resp.msg = e.getMessage();
|
|
|
+
|
|
|
+ return new ResponseEntity(resp, HttpStatus.OK);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|