Drain body after exception from applying onStatus
Closes gh-23230
This commit is contained in:
parent
2088a3d57b
commit
2aec175ccc
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -455,9 +455,15 @@ class DefaultWebClient implements WebClient {
|
|||
for (StatusHandler handler : this.statusHandlers) {
|
||||
if (handler.test(response.statusCode())) {
|
||||
HttpRequest request = this.requestSupplier.get();
|
||||
Mono<? extends Throwable> exMono = handler.apply(response, request);
|
||||
exMono = exMono.flatMap(ex -> drainBody(response, ex));
|
||||
exMono = exMono.onErrorResume(ex -> drainBody(response, ex));
|
||||
Mono<? extends Throwable> exMono;
|
||||
try {
|
||||
exMono = handler.apply(response, request);
|
||||
exMono = exMono.flatMap(ex -> drainBody(response, ex));
|
||||
exMono = exMono.onErrorResume(ex -> drainBody(response, ex));
|
||||
}
|
||||
catch (Throwable ex2) {
|
||||
exMono = drainBody(response, ex2);
|
||||
}
|
||||
return errorFunction.apply(exMono);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -147,6 +147,15 @@ public class WebClientDataBufferAllocatingTests extends AbstractDataBufferAlloca
|
|||
testOnStatus(ex, response -> response.bodyToMono(Void.class).then(Mono.error(ex)));
|
||||
}
|
||||
|
||||
@Test // gh-23230
|
||||
public void onStatusWithImmediateErrorAndBodyNotConsumed() {
|
||||
RuntimeException ex = new RuntimeException("response error");
|
||||
testOnStatus(ex, response -> {
|
||||
throw ex;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private void testOnStatus(Throwable expected,
|
||||
Function<ClientResponse, Mono<? extends Throwable>> exceptionFunction) {
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue