How to extract response body as String/Object from RestClient in case of exception?

31 Views Asked by At

Now I have it like this:

protected static ResponseEntity<?> actualResponse;
protected static RestClientResponseException actualErrorResponse;

try{
    actualResponse = REST_CLIENT.get()
            .uri(uriPath, CUSTOMER_NUMBER)
            .retrieve()
            .toEntity(payloadType);
} catch (final RestClientResponseException e) {
    actualErrorResponse = e;
}

Is there any way to extract exception in functional style?

I've tried this:

.onStatus(HttpStatusCode::isError, ((request, response) -> {
    response.getBody()

But it returns InputStream that requires addition transforming to String/Exception object.

0

There are 0 best solutions below