Applications often raise exceptions while processing requests. These exceptions must be handled properly, otherwise they will send back a HTTP 500 error to the requesting client. SpringWebFlux supports exception handling by creating methods that are annotated with @ExceptionHandler. These exception handlers can have the exception raised as an argument:
@RestControllerpublic class ReactiveController { @ExceptionHandler public String handleError(RuntimeException ex) { // ... }}
An exception handler can have the same return types as request methods. Optionally, we would like to set the HTTP status as part of exception handling, but Spring does not do this automatically. It can be accomplished by returning a ResponseEntity ...