我的ExceptionhandlingController
类带有@ControllerAdvice
注释,它们的方法带有@ExceptionHandler(ValidationException.class)
注释。我需要审核afterCompletion
类的HandlerInterceptorAdapter
方法中的请求
我的任务是使用其响应对象从ExceptionhandlingController
类获取异常,但是我在Exception
方法的afterCompletion
对象中获取空值。
我不确定如何继续进行此操作。
@ControllerAdvice
public class ExceptionHandlingController {
/**
* Resource not found.
*
* @param ex
* the ex
* @return the response entity
*/
@ExceptionHandler(ValidationException.class)
public ResponseEntity<ExceptionResponse> resourceNotFound(
ValidationException ex) {
ExceptionResponse response = new ExceptionResponse();
response.setErrorCode("Value not found");
response.setErrorMessage(messageByLocaleService.getMessage(ex
.getErrorCode()));
Map<String, String> headers = new HashMap<>();
return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST);
}
这是我的Interceptor
课
@零件
公共类AuditInterceptor扩展了HandlerInterceptorAdapter
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
throws Exception {
return true;
}
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response,
Object handler, ModelAndView modelAndView) throws Exception
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response,
Object handler, Exception ex) throws Exception {
// here I need to audit the exception, but I am getting null in Exception ex
}