I want to handle the Exception of my api by adding a WebExceptionHandler. I can change the status code, but I am stuck when i want to change the body of the response : ex adding the exception message or a custom object.
Does anyone have exemple ?
How I add my WebExceptionHandler :
HttpHandler httpHandler = WebHttpHandlerBuilder.webHandler(toHttpHandler(routerFunction))
.prependExceptionHandler((serverWebExchange, exception) -> {
exchange.getResponse().setStatusCode(myStatusGivenTheException);
exchange.getResponse().writeAndFlushWith(??)
return Mono.empty();
}).build();