Polishing
This commit is contained in:
@@ -166,7 +166,6 @@ public interface ClientResponse {
|
||||
/**
|
||||
* Creates a {@link WebClientResponseException} based on the status code,
|
||||
* headers, and body of this response as well as the corresponding request.
|
||||
*
|
||||
* @return a {@code Mono} with a {@code WebClientResponseException} based on this response
|
||||
* @since 5.2
|
||||
*/
|
||||
|
||||
@@ -190,10 +190,12 @@ class DefaultClientResponse implements ClientResponse {
|
||||
Charset charset = headers().contentType()
|
||||
.map(MimeType::getCharset)
|
||||
.orElse(StandardCharsets.ISO_8859_1);
|
||||
if (HttpStatus.resolve(rawStatusCode()) != null) {
|
||||
int statusCode = rawStatusCode();
|
||||
HttpStatus httpStatus = HttpStatus.resolve(statusCode);
|
||||
if (httpStatus != null) {
|
||||
return WebClientResponseException.create(
|
||||
statusCode().value(),
|
||||
statusCode().getReasonPhrase(),
|
||||
statusCode,
|
||||
httpStatus.getReasonPhrase(),
|
||||
headers().asHttpHeaders(),
|
||||
bodyBytes,
|
||||
charset,
|
||||
@@ -201,7 +203,7 @@ class DefaultClientResponse implements ClientResponse {
|
||||
}
|
||||
else {
|
||||
return new UnknownHttpStatusCodeException(
|
||||
rawStatusCode(),
|
||||
statusCode,
|
||||
headers().asHttpHeaders(),
|
||||
bodyBytes,
|
||||
charset,
|
||||
|
||||
@@ -64,6 +64,7 @@ final class DefaultClientResponseBuilder implements ClientResponse.Builder {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
private ExchangeStrategies strategies;
|
||||
|
||||
private HttpStatus statusCode = HttpStatus.OK;
|
||||
@@ -167,13 +168,11 @@ final class DefaultClientResponseBuilder implements ClientResponse.Builder {
|
||||
|
||||
@Override
|
||||
public ClientResponse build() {
|
||||
|
||||
ClientHttpResponse httpResponse =
|
||||
new BuiltClientHttpResponse(this.statusCode, this.headers, this.cookies, this.body);
|
||||
|
||||
// When building ClientResponse manually, the ClientRequest.logPrefix() has to be passed,
|
||||
// e.g. via ClientResponse.Builder, but this (builder) is not used currently.
|
||||
|
||||
return new DefaultClientResponse(httpResponse, this.strategies, "", "", () -> this.request);
|
||||
}
|
||||
|
||||
|
||||
@@ -440,7 +440,7 @@ class DefaultWebClient implements WebClient {
|
||||
private static IntPredicate toIntPredicate(Predicate<HttpStatus> predicate) {
|
||||
return value -> {
|
||||
HttpStatus status = HttpStatus.resolve(value);
|
||||
return (status != null) && predicate.test(status);
|
||||
return (status != null && predicate.test(status));
|
||||
};
|
||||
}
|
||||
|
||||
@@ -448,9 +448,8 @@ class DefaultWebClient implements WebClient {
|
||||
public ResponseSpec onRawStatus(IntPredicate statusCodePredicate,
|
||||
Function<ClientResponse, Mono<? extends Throwable>> exceptionFunction) {
|
||||
|
||||
Assert.notNull(statusCodePredicate, "StatusCodePredicate must not be null");
|
||||
Assert.notNull(statusCodePredicate, "IntPredicate must not be null");
|
||||
Assert.notNull(exceptionFunction, "Function must not be null");
|
||||
|
||||
this.statusHandlers.add(0, new StatusHandler(statusCodePredicate, exceptionFunction));
|
||||
return this;
|
||||
}
|
||||
@@ -563,6 +562,7 @@ class DefaultWebClient implements WebClient {
|
||||
handleBodyFlux(response, response.bodyToFlux(elementTypeRef))));
|
||||
}
|
||||
|
||||
|
||||
private static class StatusHandler {
|
||||
|
||||
private final IntPredicate predicate;
|
||||
@@ -583,7 +583,6 @@ class DefaultWebClient implements WebClient {
|
||||
public Mono<? extends Throwable> apply(ClientResponse response) {
|
||||
return this.exceptionFunction.apply(response);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -666,6 +666,7 @@ public interface WebClient {
|
||||
RequestHeadersSpec<?> syncBody(Object body);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Contract for specifying response operations following the exchange.
|
||||
*/
|
||||
@@ -799,19 +800,18 @@ public interface WebClient {
|
||||
* @since 5.2
|
||||
*/
|
||||
<T> Mono<ResponseEntity<List<T>>> toEntityList(ParameterizedTypeReference<T> elementTypeRef);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Contract for specifying request headers and URI for a request.
|
||||
*
|
||||
* @param <S> a self reference to the spec type
|
||||
*/
|
||||
interface RequestHeadersUriSpec<S extends RequestHeadersSpec<S>>
|
||||
extends UriSpec<S>, RequestHeadersSpec<S> {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Contract for specifying request headers, body and URI for a request.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user