4371 shaares
Simply add the following class to your project. It will be automatically registered at start-up if you use the @EnableAutoConfiguration
annotation :
@ControllerAdvice // Makes this the default behaviour of all controllers
@ConditionalOnProperty(prefix = "app", name = "disable-default-exception-handling")
class GlobalControllerExceptionHandler {
@ExceptionHandler(Exception.class) // Catch any exception
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) // Returns an error code …