liuxm
2024-06-06 432a1b0c4dd251f686e9bb7950c4868aaf3e4ed7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package com.dy.pmsGlobal.aop;
 
import com.dy.common.webUtil.BaseResponse;
import com.dy.common.webUtil.BaseResponseUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;
 
@ResponseBody
@RestControllerAdvice
@Slf4j
public class ExceptionHandlerAdvice {
    /**
     * 处理系统异常,兜底处理所有异常
     */
    @ExceptionHandler(value = Exception.class)
    public BaseResponse<?> defaultExceptionHandler(Throwable ex) {
        log.error("[defaultExceptionHandler]", ex);
        // 返回 ERROR
        return BaseResponseUtils.buildException(ex.getMessage());
    }
 
}