|
@@ -5,9 +5,12 @@ import com.fdkankan.fusion.exception.BusinessException;
|
|
|
import com.fdkankan.fusion.common.ResultData;
|
|
import com.fdkankan.fusion.common.ResultData;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.tomcat.util.http.fileupload.impl.IOFileUploadException;
|
|
import org.apache.tomcat.util.http.fileupload.impl.IOFileUploadException;
|
|
|
|
|
+import org.apache.tomcat.util.http.fileupload.impl.SizeLimitExceededException;
|
|
|
|
|
+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 org.springframework.web.multipart.MaxUploadSizeExceededException;
|
|
|
import org.springframework.web.multipart.MultipartException;
|
|
import org.springframework.web.multipart.MultipartException;
|
|
|
|
|
|
|
|
import java.nio.file.NoSuchFileException;
|
|
import java.nio.file.NoSuchFileException;
|
|
@@ -57,4 +60,48 @@ public class GlobalExceptionHandler {
|
|
|
log.info("NoSuchFileException:", e);
|
|
log.info("NoSuchFileException:", e);
|
|
|
return ResultData.error( ResultCode.SPACE_ERROR);
|
|
return ResultData.error( ResultCode.SPACE_ERROR);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 处理业务异常
|
|
|
|
|
+ */
|
|
|
|
|
+ @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());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 处理业务异常
|
|
|
|
|
+ */
|
|
|
|
|
+ @ResponseBody
|
|
|
|
|
+ @ExceptionHandler(value = IllegalStateException.class)
|
|
|
|
|
+ public ResultData IllegalStateExceptionExceptionException(IllegalStateException e) {
|
|
|
|
|
+ log.info("上传文件超限制-IllegalStateException:", e);
|
|
|
|
|
+ return ResultData.error(ResultCode.upload_file_limit);
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 处理业务异常
|
|
|
|
|
+ */
|
|
|
|
|
+ @ResponseBody
|
|
|
|
|
+ @ExceptionHandler(value = MaxUploadSizeExceededException.class)
|
|
|
|
|
+ public ResultData MaxUploadSizeExceededExceptionException(MaxUploadSizeExceededException e) {
|
|
|
|
|
+ log.info("上传文件超限制-MaxUploadSizeExceededException:", e);
|
|
|
|
|
+ return ResultData.error(ResultCode.upload_file_limit);
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 处理业务异常
|
|
|
|
|
+ */
|
|
|
|
|
+ @ResponseBody
|
|
|
|
|
+ @ExceptionHandler(value = SizeLimitExceededException.class)
|
|
|
|
|
+ public ResultData SizeLimitExceededExceptionException(SizeLimitExceededException e) {
|
|
|
|
|
+ log.info("上传文件超限制-SizeLimitExceededException:", e);
|
|
|
|
|
+ return ResultData.error(ResultCode.upload_file_limit);
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|