添加类型
This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user