package com.example.demo.exception.handler; import com.example.demo.exception.BadRequestException; import com.example.demo.utils.ResultVOUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; /** * @author xulei * @version 1.0 * @date 2020/9/1 13:39 */ @Slf4j @RestControllerAdvice public class GlobalExcepitonHandler { /** * 处理业务自定义异常 */ @ExceptionHandler(value = BadRequestException.class) public Object businessException(BadRequestException e) { // 打印堆栈信息 log.error("【业务异常】={}", e); return ResultVOUtil.authError(e.getCode(), e.getMessage()); } }