@ControllerAdvice @Slf4j public class CommonExceptionHandler { /** * 统一异常处理 */ @ExceptionHandler(Exception.class) @ResponseBody @ResponseStatus(code = HttpStatus.INTERNAL_SERVER_ERROR) public ResultApi exceptionHandler(Exception e){ // 程序抛出的异常 ResultApi result = checkBaseException(e); if(result == null){ // 系统内部错误 result = ResultApi.error(); } return result; } /** * 程序抛出的异常 */ private ResultApi checkBaseException(Exception e){ ResultApi result = ResultApi.error(); if(e instanceof BaseException){ result = ResultApi.error(e.getMessage()); } else { //系统错误 result = ResultApi.error(ApiResultCode.ErrorCode.SYSTEM_ERROR); log.error(e.getMessage(), e); } return result; } }