Add ClientResponse::createError
This commit introduces ClientResponse::createError, returning a Mono that terminates with a WebClientException. Closes gh-27637
This commit is contained in:
@@ -181,6 +181,18 @@ public interface ClientResponse {
|
||||
*/
|
||||
Mono<WebClientResponseException> createException();
|
||||
|
||||
/**
|
||||
* Create a {@code Mono} that terminates with a
|
||||
* {@link WebClientResponseException}, containing the response status,
|
||||
* headers, body, and the originating request.
|
||||
* @param <T> the reified type
|
||||
* @return a {@code Mono} that fails with a
|
||||
* {@link WebClientResponseException}.
|
||||
* @see #createException()
|
||||
* @since 6.0
|
||||
*/
|
||||
<T> Mono<T> createError();
|
||||
|
||||
/**
|
||||
* Return a log message prefix to use to correlate messages for this exchange.
|
||||
* <p>The prefix is based on {@linkplain ClientRequest#logPrefix()}, which
|
||||
|
||||
@@ -223,6 +223,11 @@ class DefaultClientResponse implements ClientResponse {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Mono<T> createError() {
|
||||
return createException().flatMap(Mono::error);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String logPrefix() {
|
||||
return this.logPrefix;
|
||||
|
||||
@@ -153,6 +153,11 @@ public class ClientResponseWrapper implements ClientResponse {
|
||||
return this.delegate.createException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Mono<T> createError() {
|
||||
return this.delegate.createError();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String logPrefix() {
|
||||
return this.delegate.logPrefix();
|
||||
|
||||
Reference in New Issue
Block a user