|
@@ -0,0 +1,44 @@
|
|
|
|
+package com.xynet.marketing.utils.error;
|
|
|
|
+
|
|
|
|
+import com.xynet.marketing.utils.R;
|
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
|
|
+import org.springframework.web.bind.annotation.RestControllerAdvice;
|
|
|
|
+
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
|
+
|
|
|
|
+@Slf4j
|
|
|
|
+@AllArgsConstructor
|
|
|
|
+@RestControllerAdvice
|
|
|
|
+public class ExceptionAdvice {
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 全局异常
|
|
|
|
+ *
|
|
|
|
+ * @param e
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @ExceptionHandler(Exception.class)
|
|
|
|
+ public R allException(HttpServletRequest request, HttpServletResponse response, Exception e) {
|
|
|
|
+ log.error("", e);
|
|
|
|
+ return R.fail(R.Enum.FAIL.getCode(), e.getMessage());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 通用终止异常
|
|
|
|
+ *
|
|
|
|
+ * @param e
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @ExceptionHandler(BusinessException.class)
|
|
|
|
+ public R businessException(BusinessException e) {
|
|
|
|
+ if (e.getMessage().indexOf("::") == -1) {
|
|
|
|
+ return R.fail(e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ String[] split = e.getMessage().split("::");
|
|
|
|
+ return R.fail(Integer.parseInt(split[0]), split[1]);
|
|
|
|
+ }
|
|
|
|
+}
|