I wonder if there is a better way to get error response in WebClient in a way that does not involve using additional ObjectMapper
when calling onErrorResume
?
In my WebClient:
import org.springframework.web.reactive.function.client.WebClientResponseException.BadRequest
// ...
.onErrorResume(BadRequest::class.java, badRequestToMyDto())
private fun badRequestToMyDto(): (BadRequest) -> Mono<out MyDto> =
{ it: BadRequest ->
val error = objectMapper.readValue<ErrorResponseDto>(it.responseBodyAsByteArray)
// ...
}
There is a method .bodyToMono
so I wonder if there is something similar that can be used in onErrorResume
.