From 56dd19b32e3a9e17f0991ea02ff25c7c6dd32b2a Mon Sep 17 00:00:00 2001 From: hongawen <83944980@qq.com> Date: Mon, 14 Apr 2025 08:49:54 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=96=B9=E6=B3=95=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GlobalBusinessExceptionHandler.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/entrance/src/main/java/com/njcn/gather/handler/GlobalBusinessExceptionHandler.java b/entrance/src/main/java/com/njcn/gather/handler/GlobalBusinessExceptionHandler.java index d45170b8..8ec80c33 100644 --- a/entrance/src/main/java/com/njcn/gather/handler/GlobalBusinessExceptionHandler.java +++ b/entrance/src/main/java/com/njcn/gather/handler/GlobalBusinessExceptionHandler.java @@ -64,7 +64,7 @@ public class GlobalBusinessExceptionHandler { @ExceptionHandler(BusinessException.class) public HttpResult handleBusinessException(BusinessException businessException) { String operate = ReflectCommonUtil.getMethodDescribeByException(businessException); - recodeAdviceLog(businessException, businessException.getMessage()); + recodeBusinessExceptionLog(businessException, businessException.getMessage()); return HttpResultUtil.assembleBusinessExceptionResult(businessException, null, operate); } @@ -77,7 +77,7 @@ public class GlobalBusinessExceptionHandler { @ExceptionHandler(NullPointerException.class) public HttpResult handleNullPointerException(NullPointerException 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)); } @@ -89,7 +89,7 @@ public class GlobalBusinessExceptionHandler { @ExceptionHandler(ArithmeticException.class) public HttpResult handleArithmeticException(ArithmeticException 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)); } @@ -101,7 +101,7 @@ public class GlobalBusinessExceptionHandler { @ExceptionHandler(ClassCastException.class) public HttpResult handleClassCastException(ClassCastException 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)); } @@ -114,7 +114,7 @@ public class GlobalBusinessExceptionHandler { @ExceptionHandler(IndexOutOfBoundsException.class) public HttpResult handleIndexOutOfBoundsException(IndexOutOfBoundsException 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)); } @@ -127,7 +127,7 @@ public class GlobalBusinessExceptionHandler { public HttpResult httpMediaTypeNotSupportedExceptionHandler(HttpMediaTypeNotSupportedException 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)); } @@ -144,7 +144,7 @@ public class GlobalBusinessExceptionHandler { .stream().map(ObjectError::getDefaultMessage).collect(Collectors.joining(";")); // 然后提取错误提示信息进行返回 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)); } @@ -168,7 +168,7 @@ public class GlobalBusinessExceptionHandler { } // 然后提取错误提示信息进行返回 LogUtil.njcnDebug(log, "参数校验异常,异常为:{}", messages); - recodeAdviceLog(constraintViolationException, CommonResponseEnum.METHOD_ARGUMENT_NOT_VALID_EXCEPTION.getMessage()); + recodeBusinessExceptionLog(constraintViolationException, CommonResponseEnum.METHOD_ARGUMENT_NOT_VALID_EXCEPTION.getMessage()); List> constraintViolationList = new ArrayList<>(constraintViolationException.getConstraintViolations()); ConstraintViolation constraintViolation = constraintViolationList.get(0); Class rootBeanClass = constraintViolation.getRootBeanClass(); @@ -191,7 +191,7 @@ public class GlobalBusinessExceptionHandler { @ExceptionHandler(IllegalArgumentException.class) public HttpResult handleIndexOutOfBoundsException(IllegalArgumentException 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)); } @@ -219,7 +219,7 @@ public class GlobalBusinessExceptionHandler { } } LogUtil.logExceptionStackInfo(exceptionCause, tempException); - recodeAdviceLog(exception, exceptionCause); + recodeBusinessExceptionLog(exception, exceptionCause); //判断方法上是否有自定义注解,做特殊处理 // Method method = ReflectCommonUtil.getMethod(exception); // if (!Objects.isNull(method)){ @@ -239,11 +239,11 @@ public class GlobalBusinessExceptionHandler { @ExceptionHandler(JSONException.class) public HttpResult handleIndexOutOfBoundsException(JSONException 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)); } - private void recodeAdviceLog(Exception businessException, String methodDescribe) { + private void recodeBusinessExceptionLog(Exception businessException, String methodDescribe) { HttpServletRequest httpServletRequest = HttpServletUtil.getRequest(); Future future = executor.submit(() -> { HttpServletUtil.setRequest(httpServletRequest);