I would like to retrieve response body message for...
# server
y
I would like to retrieve response body message for a given 400 status code when using the spring webclient. However, I can only find the error code and not the actual error message contained in the code. I am using following snippet. how to actually extract the response body in the 400 status response .
Copy code
val retrievedResource: Mono<String> = myRequest
            .retrieve()
            .onStatus(HttpStatus::is4xxClientError) { Mono.error(RuntimeException("4XX Error ${it.statusCode()}, ${it.bodyToMono(String::class.java)}")) }
            .onStatus(HttpStatus::is5xxServerError) { Mono.error(RuntimeException("5XX Error ${it.statusCode()}, ${it.bodyToMono(String::class.java)}")) }
        .bodyToMono(String::class.java)
        return retrievedResource.share().block()
👀 1