1、全局异常处理器
@Slf4j
@ResponseBody
@ControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler(value = BusinessExcetion.class)
public Response customExceptionHandler(BusinessExcetion businessExcetion) {
log.info(String.format("--- 业务异常 -- [%s] ---", businessExcetion.getMessage()));
return new Response(Constants.STATUS_FAIL, businessExcetion.getMessage());
}
@ExceptionHandler(value = RuntimeException.class)
public Response runtimeExceptionHandler(HttpServletRequest request,
RuntimeException runtimeException) {
log.error(String.format("--- 运行时异常(系统异常) -- [%s] ---", runtimeException.getMessage()),
runtimeException);
return new Response(Constants.STATUS_FAIL,
I18nUtil.getMessage(request, "runtime.exception.message"));
}
}
2、业务异常类
public clas