I am using Spring Boot 1.5.7. I have an ExceptionHandler for my exception that returns a ResponseEntity
@ExceptionHandler(MyException.class)
public ResponseEntity<ResponseExceptionEntity> handleException(MyException e) {
return ResponseEntity
.status(HttpStatus.BAD_REQUEST)
.body(new ResponseExceptionEntity(e));
}
This works well in situations where the exception occurs during an api call returning a ResponseEntity / @ResponseBody (JSON/XML response)
I would like to return a ModelAndView in situations where the exception occurs during a request where HTML is returned. In my situation all Controllers are annotated with @Controller and not @RestController
- how can I write a ExceptionHandler for both cases (api/html)?
- Or How can I determine what the resolved view is for a controller method?
- Or how can I determine what the return type of the Controller Method is?
- Or How can I determine what the resolved view is for the controller method?
I've tried the suggestion in this answer, but it doesn't return a JSON response when the Controller Method is annotated with @ResponseBody.