Commit ba068c353a0411ea7689cbe6a73996e541d91eb8
1 parent
e44d9fe1
feat:【framework 框架】增加对 MaxUploadSizeExceededException 文件上传过大的提示优化
Showing
1 changed file
with
12 additions
and
0 deletions
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/handler/GlobalExceptionHandler.java
| @@ -36,6 +36,7 @@ import org.springframework.web.bind.MissingServletRequestParameterException; | @@ -36,6 +36,7 @@ import org.springframework.web.bind.MissingServletRequestParameterException; | ||
| 36 | import org.springframework.web.bind.annotation.ExceptionHandler; | 36 | import org.springframework.web.bind.annotation.ExceptionHandler; |
| 37 | import org.springframework.web.bind.annotation.RestControllerAdvice; | 37 | import org.springframework.web.bind.annotation.RestControllerAdvice; |
| 38 | import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; | 38 | import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; |
| 39 | +import org.springframework.web.multipart.MaxUploadSizeExceededException; | ||
| 39 | import org.springframework.web.servlet.NoHandlerFoundException; | 40 | import org.springframework.web.servlet.NoHandlerFoundException; |
| 40 | import org.springframework.web.servlet.resource.NoResourceFoundException; | 41 | import org.springframework.web.servlet.resource.NoResourceFoundException; |
| 41 | 42 | ||
| @@ -93,6 +94,9 @@ public class GlobalExceptionHandler { | @@ -93,6 +94,9 @@ public class GlobalExceptionHandler { | ||
| 93 | if (ex instanceof ValidationException) { | 94 | if (ex instanceof ValidationException) { |
| 94 | return validationException((ValidationException) ex); | 95 | return validationException((ValidationException) ex); |
| 95 | } | 96 | } |
| 97 | + if (ex instanceof MaxUploadSizeExceededException) { | ||
| 98 | + return maxUploadSizeExceededExceptionHandler((MaxUploadSizeExceededException) ex); | ||
| 99 | + } | ||
| 96 | if (ex instanceof NoHandlerFoundException) { | 100 | if (ex instanceof NoHandlerFoundException) { |
| 97 | return noHandlerFoundExceptionHandler((NoHandlerFoundException) ex); | 101 | return noHandlerFoundExceptionHandler((NoHandlerFoundException) ex); |
| 98 | } | 102 | } |
| @@ -214,6 +218,14 @@ public class GlobalExceptionHandler { | @@ -214,6 +218,14 @@ public class GlobalExceptionHandler { | ||
| 214 | } | 218 | } |
| 215 | 219 | ||
| 216 | /** | 220 | /** |
| 221 | + * 处理上传文件过大异常 | ||
| 222 | + */ | ||
| 223 | + @ExceptionHandler(MaxUploadSizeExceededException.class) | ||
| 224 | + public CommonResult<?> maxUploadSizeExceededExceptionHandler(MaxUploadSizeExceededException ex) { | ||
| 225 | + return CommonResult.error(BAD_REQUEST.getCode(), "上传文件过大,请调整后重试"); | ||
| 226 | + } | ||
| 227 | + | ||
| 228 | + /** | ||
| 217 | * 处理 SpringMVC 请求地址不存在 | 229 | * 处理 SpringMVC 请求地址不存在 |
| 218 | * | 230 | * |
| 219 | * 注意,它需要设置如下两个配置项: | 231 | * 注意,它需要设置如下两个配置项: |