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());
|
}
|
}
|