Преглед на файлове

优化全局异常处理逻辑

woody преди 1 година
родител
ревизия
35b564e89b
променени са 1 файла, в които са добавени 3 реда и са изтрити 0 реда
  1. 3 0
      framework-base/src/main/java/com/chelvc/framework/base/interceptor/GlobalExceptionInterceptor.java

+ 3 - 0
framework-base/src/main/java/com/chelvc/framework/base/interceptor/GlobalExceptionInterceptor.java

@@ -26,6 +26,7 @@ import com.fasterxml.jackson.databind.exc.InvalidFormatException;
 import com.google.common.collect.ImmutableMap;
 import lombok.NonNull;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.TypeMismatchException;
 import org.springframework.boot.web.servlet.error.ErrorController;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.converter.HttpMessageConversionException;
@@ -163,6 +164,8 @@ public class GlobalExceptionInterceptor implements ErrorController {
                     this.format(((MethodArgumentNotValidException) e).getBindingResult()));
         } else if (e instanceof MethodArgumentTypeMismatchException) {
             return Result.build(HttpStatus.PRECONDITION_FAILED, this.format((MethodArgumentTypeMismatchException) e));
+        } else if (e instanceof TypeMismatchException) {
+            return Result.build(HttpStatus.BAD_REQUEST);
         } else if (e instanceof ParameterInvalidException) {
             return Result.build(HttpStatus.PRECONDITION_FAILED, ((ParameterInvalidException) e).getErrors());
         } else if (e instanceof MissingServletRequestPartException) {