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
for anyone looking at a way to write JSON response body, here's a Kotlin code sample:
fun writeBodyJson(body: Any, exchange: ServerWebExchange) =
exchange.response.writeWith(
Jackson2JsonEncoder().encode(
Mono.just(body),
exchange.response.bufferFactory(),
ResolvableType.forInstance(body),
MediaType.APPLICATION_JSON_UTF8,
Hints.from(Hints.LOG_PREFIX_HINT, exchange.logPrefix))
)
not 100% sure that's the way to go though, would like to get some opinions.