pull/126/MERGE
YunaiV 2024-07-19 23:37:09 +08:00
commit 3d29a981f7
1 changed files with 4 additions and 2 deletions

View File

@ -205,9 +205,11 @@ public class GlobalExceptionHandler {
*/ */
@ExceptionHandler(value = ServiceException.class) @ExceptionHandler(value = ServiceException.class)
public CommonResult<?> serviceExceptionHandler(ServiceException ex) { public CommonResult<?> serviceExceptionHandler(ServiceException ex) {
// 不包含的时候,才进行打印,避免 ex 堆栈过多
if (!IGNORE_ERROR_MESSAGES.contains(ex.getMessage())) { if (!IGNORE_ERROR_MESSAGES.contains(ex.getMessage())) {
// 不包含的时候,才进行打印,避免 ex 堆栈过多 // 即使打印,也只打印第一层 StackTraceElement并且使用 warn 在控制台输出,更容易看到
log.info("[serviceExceptionHandler]", ex); StackTraceElement[] stackTrace = ex.getStackTrace();
log.warn("[serviceExceptionHandler]\n\t{}", stackTrace[0]);
} }
return CommonResult.error(ex.getCode(), ex.getMessage()); return CommonResult.error(ex.getCode(), ex.getMessage());
} }