青羊经侦大队-数据平台
11
baizonghao
2023-05-25 7ea5eece501c98a91555a5358931367e78e9d23b
src/main/java/com/example/jz/config/DefaultExceptionHandlerConfig.java
@@ -2,6 +2,7 @@
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;
@@ -15,23 +16,15 @@
@RestControllerAdvice
public class DefaultExceptionHandlerConfig {
    @ExceptionHandler(BindException.class)
    public R<String> bindExceptionHandler(BindException e) {
        e.printStackTrace();
        return R.failed(e.getBindingResult().getFieldErrors().get(0).getDefaultMessage());
    }
    @ExceptionHandler(MethodArgumentNotValidException.class)
    public R<String> methodArgumentNotValidExceptionHandler(MethodArgumentNotValidException e) {
        e.printStackTrace();
        return R.failed(e.getBindingResult().getFieldErrors().get(0).getDefaultMessage());
    }
    @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());
    }
}