I have a Spring boot application with Thymeleaf that mixes up regular Controller calls that request lookup and REST asynchronous calls. To handle errors in asynchronous REST calls, I would like to provide a property as a reason for handling exceptions and automatically translate it using MessageSource.
My handler is as follows.
@ExceptionHandler(Exception.class) @ResponseStatus(value = HttpStatus.BAD_REQUEST, reason = "general.unexpected.exception") public ModelAndView handleUnexpectedException(Exception exception) { logger.error(exception.getMessage(), exception); return createModelAndView("error"); }
When an error occurs as part of a normal controller call, an error message is displayed. But in the case of Javascript REST calls, I would like to be able to replace the reason general.unexpected.exception with the appropriate text based on the user locale, for example, "An unexpected error occurred", so I can display this in the interface in my javascript () failure in case of an unhandled mistakes.
Any clue on how to do this would be greatly appreciated. Thanks!
Damien polegato
source share