return new WebClientResponseException(statusCode, statusText, headers, body, charset, request);
.defaultIfEmpty(new byte[0]) .map(bodyBytes -> { throw new WebClientResponseException( "ClientResponse has erroneous status code: " + httpStatus.value() + " "
public static Mono<ClientResponse> checkStatus(ClientResponse response, Predicate<HttpStatus> statusPredicate) { if (statusPredicate.test(response.statusCode())) { return Mono.just(response); } Charset charset = response.headers().contentType() .map(MimeType::getCharset) .orElse(StandardCharsets.ISO_8859_1); return response.bodyToMono(byte[].class) .flatMap(body -> Mono.error(new WebClientResponseException( "Unexpected response", response.statusCode().value(), response.statusCode().getReasonPhrase(), response.headers().asHttpHeaders(), body, charset ))); }