Commit a8fc7982ff680ba564030612a7414f967d53d385
1 parent
047051e0
【功能优化】全局:简化 GlobalExceptionHandler 对 ServiceException 的打印
Showing
1 changed file
with
4 additions
and
2 deletions
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/handler/GlobalExceptionHandler.java
| ... | ... | @@ -219,9 +219,11 @@ public class GlobalExceptionHandler { |
| 219 | 219 | */ |
| 220 | 220 | @ExceptionHandler(value = ServiceException.class) |
| 221 | 221 | public CommonResult<?> serviceExceptionHandler(ServiceException ex) { |
| 222 | + // 不包含的时候,才进行打印,避免 ex 堆栈过多 | |
| 222 | 223 | if (!IGNORE_ERROR_MESSAGES.contains(ex.getMessage())) { |
| 223 | - // 不包含的时候,才进行打印,避免 ex 堆栈过多 | |
| 224 | - log.info("[serviceExceptionHandler]", ex); | |
| 224 | + // 即使打印,也只打印第一层 StackTraceElement,并且使用 warn 在控制台输出,更容易看到 | |
| 225 | + StackTraceElement[] stackTrace = ex.getStackTrace(); | |
| 226 | + log.warn("[serviceExceptionHandler]\n\t{}", stackTrace[0]); | |
| 225 | 227 | } |
| 226 | 228 | return CommonResult.error(ex.getCode(), ex.getMessage()); |
| 227 | 229 | } | ... | ... |