|
@@ -0,0 +1,40 @@
|
|
|
+package com.github.jfcloud.gene.config;
|
|
|
+
|
|
|
+import com.github.jfcloud.common.core.util.R;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.ibatis.exceptions.PersistenceException;
|
|
|
+import org.springframework.core.annotation.Order;
|
|
|
+import org.springframework.web.bind.annotation.ControllerAdvice;
|
|
|
+import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
|
+import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 异常捕获
|
|
|
+ * @see com.github.jfcloud.common.exception.GlobalExceptionHandler
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Order(2)
|
|
|
+@ControllerAdvice
|
|
|
+public class ExHandler {
|
|
|
+
|
|
|
+ @ResponseBody
|
|
|
+ @ExceptionHandler({PersistenceException.class})
|
|
|
+ public R persistenceException(HttpServletRequest h, Exception e) {
|
|
|
+ log.error("Mysql执行异常:{}", h.getRequestURI());
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
+ if (e.getMessage().contains("Data too long for column")) {
|
|
|
+ return R.failed("数据长度超出数据库字段长度限制");
|
|
|
+ }
|
|
|
+ return R.failed(e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ @ResponseBody
|
|
|
+ @ExceptionHandler({Exception.class})
|
|
|
+ public R globalException(HttpServletRequest h, Exception e) {
|
|
|
+ log.error("{} 发生错误", h.getRequestURI());
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
+ return R.failed(e.getMessage());
|
|
|
+ }
|
|
|
+}
|