添加类型

This commit is contained in:
韩鹏辉
2024-06-14 15:28:13 +08:00
parent e5f5317f4e
commit 90a8fd4a54
10 changed files with 874 additions and 3 deletions

View File

@@ -0,0 +1,42 @@
package com.chaozhanggui.system.cashierservice.exception;
import com.chaozhanggui.system.cashierservice.sign.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* 统一异常处理
* ControllerAdvice注解的含义是当异常抛到controller层时会拦截下来
*/
@ControllerAdvice
public class GlobalExceptionHandler {
/**
* 使用ExceptionHandler注解声明处理Exception异常
*
*/
@ResponseBody
@ExceptionHandler(Exception.class)
public Result exception(Exception e) {
// 控制台打印异常
e.printStackTrace();
// 返回错误格式信息
return Result.fail("系统内部错误");
}
/**
* 使用ExceptionHandler注解声明处理TestException异常
*
*/
@ResponseBody
@ExceptionHandler(MsgException.class)
public Result exception(MsgException e) {
// 控制台打印异常
e.printStackTrace();
// 返回错误格式信息
return Result.fail(e.getMessage());
}
}