diff --git a/src/main/java/com/ycwl/basic/exception/CustomExceptionHandle.java b/src/main/java/com/ycwl/basic/exception/CustomExceptionHandle.java index 581a35b..568e056 100644 --- a/src/main/java/com/ycwl/basic/exception/CustomExceptionHandle.java +++ b/src/main/java/com/ycwl/basic/exception/CustomExceptionHandle.java @@ -2,6 +2,7 @@ package com.ycwl.basic.exception; import com.ycwl.basic.enums.BizCodeEnum; import com.ycwl.basic.utils.ApiResponse; +import jakarta.servlet.http.HttpServletRequest; import org.apache.tomcat.util.http.fileupload.impl.SizeLimitExceededException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -11,6 +12,8 @@ import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; import jakarta.servlet.http.HttpServletResponse; +import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; + import java.io.IOException; /** @@ -54,6 +57,12 @@ public class CustomExceptionHandle { response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); return ApiResponse.buildResponse(bizException.getCode(), bizException.getMsg()); } + @ExceptionHandler(value = MethodArgumentTypeMismatchException.class) + public ApiResponse handle(HttpServletRequest request, HttpServletResponse response, MethodArgumentTypeMismatchException exception) { + response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); + LOGGER.error("参数错误 -> 请求地址:{},请求方式:{}", request.getRequestURI(), request.getMethod()); + return ApiResponse.buildResponse(5000, "参数错误!"); + } @ExceptionHandler(value =IOException.class) public ApiResponse handle(HttpServletResponse response, IOException e) {