青羊经侦大队-数据平台
baizonghao
2023-05-19 1c3f11dfd7493a4c4a8d41e2499477840bcc070c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package com.example.jz.config;
 
import com.example.jz.exception.BusinessException;
import com.example.jz.modle.R;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindException;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
 
/**
 * 自定义错误处理器
 */
@Controller
@RestControllerAdvice
public class DefaultExceptionHandlerConfig {
 
    @ExceptionHandler(BusinessException.class)
    public R<String> unauthorizedExceptionHandler(BusinessException e) {
        e.printStackTrace();
        return R.failed(e.getMessage());
    }
 
    @ExceptionHandler(Exception.class)
    public R<String> ExceptionHandler(Exception e) {
        e.printStackTrace();
        return R.failed(e.getMessage());
    }
}