增加异常反打实现,避免异常堆栈信息过长
This commit is contained in:
@@ -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异常
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user