|
@@ -135,6 +135,7 @@ public class GlobalExceptionHandler {
|
|
|
return commonResult(errorCode.getCode(), errorCode.getMsg());
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 处理 SpringMVC 请求参数缺失
|
|
|
* <p>
|
|
@@ -144,7 +145,7 @@ public class GlobalExceptionHandler {
|
|
|
public CommonResult<?> missingServletRequestParameterExceptionHandler(MissingServletRequestParameterException ex) {
|
|
|
log.warn("[missingServletRequestParameterExceptionHandler]", ex);
|
|
|
// return CommonResult.error(BAD_REQUEST.getCode(), String.format("请求参数缺失:%s", ex.getParameterName()));
|
|
|
- return commonResult(BAD_REQUEST.getCode(), ex.getParameterName());
|
|
|
+ return CommonResult.error(BAD_REQUEST.getCode(), String.format("%s", ex.getParameterName()));
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -156,7 +157,7 @@ public class GlobalExceptionHandler {
|
|
|
public CommonResult<?> methodArgumentTypeMismatchExceptionHandler(MethodArgumentTypeMismatchException ex) {
|
|
|
log.warn("[missingServletRequestParameterExceptionHandler]", ex);
|
|
|
// return CommonResult.error(BAD_REQUEST.getCode(), String.format("请求参数类型错误:%s", ex.getMessage()));
|
|
|
- return commonResult(BAD_REQUEST.getCode(), ex.getMessage());
|
|
|
+ return CommonResult.error(BAD_REQUEST.getCode(), String.format("%s", ex.getMessage()));
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -168,7 +169,7 @@ public class GlobalExceptionHandler {
|
|
|
FieldError fieldError = ex.getBindingResult().getFieldError();
|
|
|
assert fieldError != null; // 断言,避免告警
|
|
|
// return CommonResult.error(BAD_REQUEST.getCode(), String.format("请求参数不正确:%s", fieldError.getDefaultMessage()));
|
|
|
- return commonResult(BAD_REQUEST.getCode(), fieldError.getDefaultMessage());
|
|
|
+ return CommonResult.error(BAD_REQUEST.getCode(), String.format("%s", fieldError.getDefaultMessage()));
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -180,7 +181,7 @@ public class GlobalExceptionHandler {
|
|
|
FieldError fieldError = ex.getFieldError();
|
|
|
assert fieldError != null; // 断言,避免告警
|
|
|
// return CommonResult.error(BAD_REQUEST.getCode(), String.format("请求参数不正确:%s", fieldError.getDefaultMessage()));
|
|
|
- return commonResult(BAD_REQUEST.getCode(), fieldError.getDefaultMessage());
|
|
|
+ return CommonResult.error(BAD_REQUEST.getCode(), String.format("%s", fieldError.getDefaultMessage()));
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -191,7 +192,7 @@ public class GlobalExceptionHandler {
|
|
|
log.warn("[constraintViolationExceptionHandler]", ex);
|
|
|
ConstraintViolation<?> constraintViolation = ex.getConstraintViolations().iterator().next();
|
|
|
// return CommonResult.error(BAD_REQUEST.getCode(), String.format("请求参数不正确:%s", constraintViolation.getMessage()));
|
|
|
- return commonResult(BAD_REQUEST.getCode(), constraintViolation.getMessage());
|
|
|
+ return CommonResult.error(BAD_REQUEST.getCode(), String.format("%s", constraintViolation.getMessage()));
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -215,7 +216,7 @@ public class GlobalExceptionHandler {
|
|
|
public CommonResult<?> noHandlerFoundExceptionHandler(NoHandlerFoundException ex) {
|
|
|
log.warn("[noHandlerFoundExceptionHandler]", ex);
|
|
|
// return CommonResult.error(NOT_FOUND.getCode(), String.format("请求地址不存在:%s", ex.getRequestURL()));
|
|
|
- return commonResult(NOT_FOUND.getCode(), ex.getRequestURL());
|
|
|
+ return CommonResult.error(NOT_FOUND.getCode(), String.format("%s", ex.getRequestURL()));
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -227,7 +228,7 @@ public class GlobalExceptionHandler {
|
|
|
public CommonResult<?> httpRequestMethodNotSupportedExceptionHandler(HttpRequestMethodNotSupportedException ex) {
|
|
|
log.warn("[httpRequestMethodNotSupportedExceptionHandler]", ex);
|
|
|
// return CommonResult.error(METHOD_NOT_ALLOWED.getCode(), String.format("请求方法不正确:%s", ex.getMessage()));
|
|
|
- return commonResult(METHOD_NOT_ALLOWED.getCode(), ex.getMessage());
|
|
|
+ return CommonResult.error(METHOD_NOT_ALLOWED.getCode(), String.format("%s", ex.getMessage()));
|
|
|
}
|
|
|
|
|
|
/**
|