|
@@ -1,11 +1,15 @@
|
|
package com.fdkankan.manage.exception;
|
|
package com.fdkankan.manage.exception;
|
|
|
|
|
|
|
|
+import com.fdkankan.manage.common.ResultCode;
|
|
import com.fdkankan.manage.common.ResultData;
|
|
import com.fdkankan.manage.common.ResultData;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.springframework.dao.DataIntegrityViolationException;
|
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
|
|
|
|
|
|
|
+import java.util.Objects;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 全局异常处理器
|
|
* 全局异常处理器
|
|
*/
|
|
*/
|
|
@@ -32,4 +36,16 @@ public class GlobalExceptionHandler {
|
|
log.info("业务异常code:{},message:{}", e.getCode(), e.getMessage());
|
|
log.info("业务异常code:{},message:{}", e.getCode(), e.getMessage());
|
|
return ResultData.error(e.getCode(), e.getMessage());
|
|
return ResultData.error(e.getCode(), e.getMessage());
|
|
}
|
|
}
|
|
|
|
+ /**
|
|
|
|
+ * 处理业务异常
|
|
|
|
+ */
|
|
|
|
+ @ResponseBody
|
|
|
|
+ @ExceptionHandler(value = DataIntegrityViolationException.class)
|
|
|
|
+ public ResultData DataIntegrityViolationExceptionHandler(DataIntegrityViolationException e) {
|
|
|
|
+ log.error("mysql服务错误:", e);
|
|
|
|
+ if(e.getCause().getMessage().contains("Data too long")){
|
|
|
|
+ return ResultData.error(ResultCode.DATA_TOO_LONG);
|
|
|
|
+ }
|
|
|
|
+ return ResultData.error( 500, e.getCause().getMessage());
|
|
|
|
+ }
|
|
}
|
|
}
|