Is there a way to get access to the RequestBody
(preferably in it's mapped form) in an @ExceptionHandler
method using Spring WebFlux, with the default Reactor Netty?
Consider the following example:
@RestController
class TestRestController {
@PostMapping("/test")
Mono<TestBody> testPost(@RequestBody TestBody testBody) {
return Mono.error(new NullPointerException());
}
@ExceptionHandler(NullPointerException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
Mono<Void> handleNullPointerException(ServerWebExchange serverWebExchange) {
return Mono.empty();
}
}
At runtime additional instances of certain types can be injected into the @ExceptionHandler
's method signature, as shown in the above example with ServerWebExchange
. But the docs clearly state that it doesn't support request body arguments (see the note in this section).
Using the Servlet stack, you can inject the RequestContext
as shown here. Is there an equivalent or similar approach for the WebFlux stack?