mica-boot 通用异常处理

使用 @RestControllerAdvice@ExceptionHandler 进行的异常处理,处理成 R 结构。

通用异常

  1. 高优先级的异常(不能再自定义)
MissingServletRequestParameterException.class

MethodArgumentTypeMismatchException.class

MethodArgumentNotValidException.class

BindException.class

ConstraintViolationException.class

NoHandlerFoundException.class

HttpMessageNotReadableException.class

HttpRequestMethodNotSupportedException.class

HttpMediaTypeNotSupportedException.class

HttpMediaTypeNotAcceptableException.class
  1. 低优先级的异常(可自定义重写)
ServiceException.class

Throwable.class

未知异常监听

对 ServiceException 和 Throwable 非自定义的异常可以监听 Event。

/**
* mica 异常事件监听器
*/
@Configuration
public class MicaErrorEventListener {

/**
* 建议使用 异步
* @param event MicaErrorEvent
*/
@Async
@EventListener(MicaErrorEvent.class)
public void handleError(MicaErrorEvent event) {

}

}

微信公众号

如梦技术

精彩内容每日推荐!!!