diff --git a/cash-common/cash-common-api-config/src/main/java/com/czg/exception/CzgControllerAdvice.java b/cash-common/cash-common-api-config/src/main/java/com/czg/exception/CzgControllerAdvice.java index b806ab5e5..a8b305df8 100644 --- a/cash-common/cash-common-api-config/src/main/java/com/czg/exception/CzgControllerAdvice.java +++ b/cash-common/cash-common-api-config/src/main/java/com/czg/exception/CzgControllerAdvice.java @@ -14,6 +14,7 @@ import org.springframework.http.converter.HttpMessageNotReadableException; import org.springframework.validation.ObjectError; import org.springframework.web.HttpRequestMethodNotSupportedException; import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.MissingServletRequestParameterException; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseStatus; @@ -63,14 +64,14 @@ public class CzgControllerAdvice { @ResponseBody @ExceptionHandler(value = NotPermissionException.class) @ResponseStatus(HttpStatus.OK) - public CzgResult notPermissionErrorHandler(NotPermissionException ex) { + public CzgResult notPermissionErrorHandler() { return CzgResult.failure(CzgRespCode.UN_PERMISSION); } @ResponseBody @ExceptionHandler(value = NotRoleException.class) @ResponseStatus(HttpStatus.OK) - public CzgResult notRoleErrorHandler(NotRoleException ex) { + public CzgResult notRoleErrorHandler() { return CzgResult.failure(CzgRespCode.UN_ROLE); } @@ -118,6 +119,12 @@ public class CzgControllerAdvice { return CzgResult.failure(701, "订单已过期,请重新下单"); } + @ExceptionHandler(MissingServletRequestParameterException.class) + public CzgResult handleMissingServletRequestParameterException(MissingServletRequestParameterException ex) { + log.error("传参错误", ex); + return CzgResult.failure(CzgRespCode.SYSTEM_ERROR.getCode(), "系统繁忙,请稍后再试"); + } + /** * 处理Hutool的断言抛出异常 */ @@ -156,7 +163,7 @@ public class CzgControllerAdvice { public CzgResult errorHandler(Exception ex) { // setErrorLog(ex); // 3. 处理未捕获的异常(系统异常,隐藏敏感信息) - log.error("系统未处理异常", ex); // 替换原有 setErrorLog,使用日志框架 + log.error("系统未处理异常", ex); return CzgResult.failure(CzgRespCode.SYSTEM_ERROR.getCode(), "系统繁忙,请稍后再试"); }