I would like to retrieve response body message for a given 400 status code when using the spring web...
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()
This is one of the messages for a 400 code
g
@Yogeshvu did you check if
onStatus
allows you to get a throwable or some other object inside the lambda?
y
I tried.. but was not able to find one.
420 Views