I use the default AnnotationMethodHandlerAdapter parameter, which I believe should support @ExceptionHandler support. Unfortunately, a ServletRequestBindingException is thrown if a handler method call like the one below is called, rather than an Exception handler.
@RequestMapping(value = "/v1/products/{code}", method = RequestMethod.GET, headers = "Accept=application/xml,application/json")
@ResponseBody
public ProductDemoDTO getProductByCode(@PathVariable final String code,
@RequestParam(required = false, defaultValue = "BASIC") final String options)
{
}
In this case, the ExceptionHandler never raised:
@ExceptionHandler(Throwable.class)
@ResponseBody
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
public void handleException(final Exception e, final HttpServletRequest request, final Writer writer) throws IOException
{
writer.write(String.format("{\"error\":{\"java.class\":\"%s\", \"message\":\"%s\"}}", e.getClass(), e.getMessage()));
}
Does anyone know why the ExceptionHandler is not called?
source
share