调整方法名

This commit is contained in:
2025-04-14 08:49:54 +08:00
parent 8460574f10
commit 56dd19b32e

View File

@@ -64,7 +64,7 @@ public class GlobalBusinessExceptionHandler {
@ExceptionHandler(BusinessException.class) @ExceptionHandler(BusinessException.class)
public HttpResult<String> handleBusinessException(BusinessException businessException) { public HttpResult<String> handleBusinessException(BusinessException businessException) {
String operate = ReflectCommonUtil.getMethodDescribeByException(businessException); String operate = ReflectCommonUtil.getMethodDescribeByException(businessException);
recodeAdviceLog(businessException, businessException.getMessage()); recodeBusinessExceptionLog(businessException, businessException.getMessage());
return HttpResultUtil.assembleBusinessExceptionResult(businessException, null, operate); return HttpResultUtil.assembleBusinessExceptionResult(businessException, null, operate);
} }
@@ -77,7 +77,7 @@ public class GlobalBusinessExceptionHandler {
@ExceptionHandler(NullPointerException.class) @ExceptionHandler(NullPointerException.class)
public HttpResult<String> handleNullPointerException(NullPointerException nullPointerException) { public HttpResult<String> handleNullPointerException(NullPointerException nullPointerException) {
LogUtil.logExceptionStackInfo(CommonResponseEnum.NULL_POINTER_EXCEPTION.getMessage(), nullPointerException); LogUtil.logExceptionStackInfo(CommonResponseEnum.NULL_POINTER_EXCEPTION.getMessage(), nullPointerException);
recodeAdviceLog(nullPointerException, CommonResponseEnum.NULL_POINTER_EXCEPTION.getMessage()); recodeBusinessExceptionLog(nullPointerException, CommonResponseEnum.NULL_POINTER_EXCEPTION.getMessage());
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.NULL_POINTER_EXCEPTION, null, ReflectCommonUtil.getMethodDescribeByException(nullPointerException)); return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.NULL_POINTER_EXCEPTION, null, ReflectCommonUtil.getMethodDescribeByException(nullPointerException));
} }
@@ -89,7 +89,7 @@ public class GlobalBusinessExceptionHandler {
@ExceptionHandler(ArithmeticException.class) @ExceptionHandler(ArithmeticException.class)
public HttpResult<String> handleArithmeticException(ArithmeticException arithmeticException) { public HttpResult<String> handleArithmeticException(ArithmeticException arithmeticException) {
LogUtil.logExceptionStackInfo(CommonResponseEnum.ARITHMETIC_EXCEPTION.getMessage(), arithmeticException); LogUtil.logExceptionStackInfo(CommonResponseEnum.ARITHMETIC_EXCEPTION.getMessage(), arithmeticException);
recodeAdviceLog(arithmeticException, CommonResponseEnum.ARITHMETIC_EXCEPTION.getMessage()); recodeBusinessExceptionLog(arithmeticException, CommonResponseEnum.ARITHMETIC_EXCEPTION.getMessage());
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.ARITHMETIC_EXCEPTION, null, ReflectCommonUtil.getMethodDescribeByException(arithmeticException)); return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.ARITHMETIC_EXCEPTION, null, ReflectCommonUtil.getMethodDescribeByException(arithmeticException));
} }
@@ -101,7 +101,7 @@ public class GlobalBusinessExceptionHandler {
@ExceptionHandler(ClassCastException.class) @ExceptionHandler(ClassCastException.class)
public HttpResult<String> handleClassCastException(ClassCastException classCastException) { public HttpResult<String> handleClassCastException(ClassCastException classCastException) {
LogUtil.logExceptionStackInfo(CommonResponseEnum.CLASS_CAST_EXCEPTION.getMessage(), classCastException); LogUtil.logExceptionStackInfo(CommonResponseEnum.CLASS_CAST_EXCEPTION.getMessage(), classCastException);
recodeAdviceLog(classCastException, CommonResponseEnum.CLASS_CAST_EXCEPTION.getMessage()); recodeBusinessExceptionLog(classCastException, CommonResponseEnum.CLASS_CAST_EXCEPTION.getMessage());
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.CLASS_CAST_EXCEPTION, null, ReflectCommonUtil.getMethodDescribeByException(classCastException)); return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.CLASS_CAST_EXCEPTION, null, ReflectCommonUtil.getMethodDescribeByException(classCastException));
} }
@@ -114,7 +114,7 @@ public class GlobalBusinessExceptionHandler {
@ExceptionHandler(IndexOutOfBoundsException.class) @ExceptionHandler(IndexOutOfBoundsException.class)
public HttpResult<String> handleIndexOutOfBoundsException(IndexOutOfBoundsException indexOutOfBoundsException) { public HttpResult<String> handleIndexOutOfBoundsException(IndexOutOfBoundsException indexOutOfBoundsException) {
LogUtil.logExceptionStackInfo(CommonResponseEnum.INDEX_OUT_OF_BOUNDS_EXCEPTION.getMessage(), indexOutOfBoundsException); LogUtil.logExceptionStackInfo(CommonResponseEnum.INDEX_OUT_OF_BOUNDS_EXCEPTION.getMessage(), indexOutOfBoundsException);
recodeAdviceLog(indexOutOfBoundsException, CommonResponseEnum.INDEX_OUT_OF_BOUNDS_EXCEPTION.getMessage()); recodeBusinessExceptionLog(indexOutOfBoundsException, CommonResponseEnum.INDEX_OUT_OF_BOUNDS_EXCEPTION.getMessage());
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.INDEX_OUT_OF_BOUNDS_EXCEPTION, null, ReflectCommonUtil.getMethodDescribeByException(indexOutOfBoundsException)); return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.INDEX_OUT_OF_BOUNDS_EXCEPTION, null, ReflectCommonUtil.getMethodDescribeByException(indexOutOfBoundsException));
} }
@@ -127,7 +127,7 @@ public class GlobalBusinessExceptionHandler {
public HttpResult<String> httpMediaTypeNotSupportedExceptionHandler(HttpMediaTypeNotSupportedException httpMediaTypeNotSupportedException) { public HttpResult<String> httpMediaTypeNotSupportedExceptionHandler(HttpMediaTypeNotSupportedException httpMediaTypeNotSupportedException) {
LogUtil.logExceptionStackInfo(CommonResponseEnum.HTTP_MEDIA_TYPE_NOT_SUPPORTED_EXCEPTION.getMessage(), httpMediaTypeNotSupportedException); LogUtil.logExceptionStackInfo(CommonResponseEnum.HTTP_MEDIA_TYPE_NOT_SUPPORTED_EXCEPTION.getMessage(), httpMediaTypeNotSupportedException);
// 然后提取错误提示信息进行返回 // 然后提取错误提示信息进行返回
recodeAdviceLog(httpMediaTypeNotSupportedException, CommonResponseEnum.HTTP_MEDIA_TYPE_NOT_SUPPORTED_EXCEPTION.getMessage()); recodeBusinessExceptionLog(httpMediaTypeNotSupportedException, CommonResponseEnum.HTTP_MEDIA_TYPE_NOT_SUPPORTED_EXCEPTION.getMessage());
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.HTTP_MEDIA_TYPE_NOT_SUPPORTED_EXCEPTION, null, ReflectCommonUtil.getMethodDescribeByException(httpMediaTypeNotSupportedException)); return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.HTTP_MEDIA_TYPE_NOT_SUPPORTED_EXCEPTION, null, ReflectCommonUtil.getMethodDescribeByException(httpMediaTypeNotSupportedException));
} }
@@ -144,7 +144,7 @@ public class GlobalBusinessExceptionHandler {
.stream().map(ObjectError::getDefaultMessage).collect(Collectors.joining("")); .stream().map(ObjectError::getDefaultMessage).collect(Collectors.joining(""));
// 然后提取错误提示信息进行返回 // 然后提取错误提示信息进行返回
LogUtil.njcnDebug(log, "参数校验异常,异常为:{}", messages); LogUtil.njcnDebug(log, "参数校验异常,异常为:{}", messages);
recodeAdviceLog(methodArgumentNotValidException, CommonResponseEnum.METHOD_ARGUMENT_NOT_VALID_EXCEPTION.getMessage()); recodeBusinessExceptionLog(methodArgumentNotValidException, CommonResponseEnum.METHOD_ARGUMENT_NOT_VALID_EXCEPTION.getMessage());
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.METHOD_ARGUMENT_NOT_VALID_EXCEPTION, messages, ControllerUtil.getMethodArgumentNotValidException(methodArgumentNotValidException)); return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.METHOD_ARGUMENT_NOT_VALID_EXCEPTION, messages, ControllerUtil.getMethodArgumentNotValidException(methodArgumentNotValidException));
} }
@@ -168,7 +168,7 @@ public class GlobalBusinessExceptionHandler {
} }
// 然后提取错误提示信息进行返回 // 然后提取错误提示信息进行返回
LogUtil.njcnDebug(log, "参数校验异常,异常为:{}", messages); LogUtil.njcnDebug(log, "参数校验异常,异常为:{}", messages);
recodeAdviceLog(constraintViolationException, CommonResponseEnum.METHOD_ARGUMENT_NOT_VALID_EXCEPTION.getMessage()); recodeBusinessExceptionLog(constraintViolationException, CommonResponseEnum.METHOD_ARGUMENT_NOT_VALID_EXCEPTION.getMessage());
List<ConstraintViolation<?>> constraintViolationList = new ArrayList<>(constraintViolationException.getConstraintViolations()); List<ConstraintViolation<?>> constraintViolationList = new ArrayList<>(constraintViolationException.getConstraintViolations());
ConstraintViolation<?> constraintViolation = constraintViolationList.get(0); ConstraintViolation<?> constraintViolation = constraintViolationList.get(0);
Class<?> rootBeanClass = constraintViolation.getRootBeanClass(); Class<?> rootBeanClass = constraintViolation.getRootBeanClass();
@@ -191,7 +191,7 @@ public class GlobalBusinessExceptionHandler {
@ExceptionHandler(IllegalArgumentException.class) @ExceptionHandler(IllegalArgumentException.class)
public HttpResult<String> handleIndexOutOfBoundsException(IllegalArgumentException illegalArgumentException) { public HttpResult<String> handleIndexOutOfBoundsException(IllegalArgumentException illegalArgumentException) {
LogUtil.logExceptionStackInfo(CommonResponseEnum.ILLEGAL_ARGUMENT_EXCEPTION.getMessage(), illegalArgumentException); LogUtil.logExceptionStackInfo(CommonResponseEnum.ILLEGAL_ARGUMENT_EXCEPTION.getMessage(), illegalArgumentException);
recodeAdviceLog(illegalArgumentException, CommonResponseEnum.ILLEGAL_ARGUMENT_EXCEPTION.getMessage()); recodeBusinessExceptionLog(illegalArgumentException, CommonResponseEnum.ILLEGAL_ARGUMENT_EXCEPTION.getMessage());
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.ILLEGAL_ARGUMENT_EXCEPTION, illegalArgumentException.getMessage(), ReflectCommonUtil.getMethodDescribeByException(illegalArgumentException)); return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.ILLEGAL_ARGUMENT_EXCEPTION, illegalArgumentException.getMessage(), ReflectCommonUtil.getMethodDescribeByException(illegalArgumentException));
} }
@@ -219,7 +219,7 @@ public class GlobalBusinessExceptionHandler {
} }
} }
LogUtil.logExceptionStackInfo(exceptionCause, tempException); LogUtil.logExceptionStackInfo(exceptionCause, tempException);
recodeAdviceLog(exception, exceptionCause); recodeBusinessExceptionLog(exception, exceptionCause);
//判断方法上是否有自定义注解,做特殊处理 //判断方法上是否有自定义注解,做特殊处理
// Method method = ReflectCommonUtil.getMethod(exception); // Method method = ReflectCommonUtil.getMethod(exception);
// if (!Objects.isNull(method)){ // if (!Objects.isNull(method)){
@@ -239,11 +239,11 @@ public class GlobalBusinessExceptionHandler {
@ExceptionHandler(JSONException.class) @ExceptionHandler(JSONException.class)
public HttpResult<String> handleIndexOutOfBoundsException(JSONException jsonException) { public HttpResult<String> handleIndexOutOfBoundsException(JSONException jsonException) {
LogUtil.logExceptionStackInfo(CommonResponseEnum.JSON_CONVERT_EXCEPTION.getMessage(), jsonException); LogUtil.logExceptionStackInfo(CommonResponseEnum.JSON_CONVERT_EXCEPTION.getMessage(), jsonException);
recodeAdviceLog(jsonException, CommonResponseEnum.JSON_CONVERT_EXCEPTION.getMessage()); recodeBusinessExceptionLog(jsonException, CommonResponseEnum.JSON_CONVERT_EXCEPTION.getMessage());
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.JSON_CONVERT_EXCEPTION, jsonException.getMessage(), ReflectCommonUtil.getMethodDescribeByException(jsonException)); return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.JSON_CONVERT_EXCEPTION, jsonException.getMessage(), ReflectCommonUtil.getMethodDescribeByException(jsonException));
} }
private void recodeAdviceLog(Exception businessException, String methodDescribe) { private void recodeBusinessExceptionLog(Exception businessException, String methodDescribe) {
HttpServletRequest httpServletRequest = HttpServletUtil.getRequest(); HttpServletRequest httpServletRequest = HttpServletUtil.getRequest();
Future<?> future = executor.submit(() -> { Future<?> future = executor.submit(() -> {
HttpServletUtil.setRequest(httpServletRequest); HttpServletUtil.setRequest(httpServletRequest);