【功能优化】全局:简化 GlobalExceptionHandler 对 ServiceException 的打印
							parent
							
								
									f6ff5086be
								
							
						
					
					
						commit
						825be64d6d
					
				| 
						 | 
				
			
			@ -219,9 +219,11 @@ public class GlobalExceptionHandler {
 | 
			
		|||
     */
 | 
			
		||||
    @ExceptionHandler(value = ServiceException.class)
 | 
			
		||||
    public CommonResult<?> serviceExceptionHandler(ServiceException ex) {
 | 
			
		||||
        if (!IGNORE_ERROR_MESSAGES.contains(ex.getMessage())) {
 | 
			
		||||
        // 不包含的时候,才进行打印,避免 ex 堆栈过多
 | 
			
		||||
            log.info("[serviceExceptionHandler]", ex);
 | 
			
		||||
        if (!IGNORE_ERROR_MESSAGES.contains(ex.getMessage())) {
 | 
			
		||||
            // 即使打印,也只打印第一层 StackTraceElement,并且使用 warn 在控制台输出,更容易看到
 | 
			
		||||
            StackTraceElement[] stackTrace = ex.getStackTrace();
 | 
			
		||||
            log.warn("[serviceExceptionHandler]\n\t{}", stackTrace[0]);
 | 
			
		||||
        }
 | 
			
		||||
        return CommonResult.error(ex.getCode(), ex.getMessage());
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue