增加异常反打实现,避免异常堆栈信息过长

This commit is contained in:
2024-09-24 09:56:27 +08:00
parent ca49d31260
commit a27f64dafa
3 changed files with 107 additions and 9 deletions

View File

@@ -2,6 +2,7 @@ package com.chaozhanggui.system.cashierservice.exception;
import com.chaozhanggui.system.cashierservice.sign.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
@@ -11,6 +12,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
* ControllerAdvice注解的含义是当异常抛到controller层时会拦截下来
*/
@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
/**
@@ -26,6 +28,14 @@ public class GlobalExceptionHandler {
return Result.fail("系统内部错误");
}
@ResponseBody
@ExceptionHandler(NotPrintException.class)
public Result exceptionNotPrint(Exception e) {
log.warn("获取到不打印堆栈异常, 异常信息: {}", e.getMessage());
// 返回错误格式信息
return Result.fail(e.getMessage());
}
/**
* 使用ExceptionHandler注解声明处理TestException异常
*