Merge branch '5.1.x'

This commit is contained in:
Rossen Stoyanchev
2019-07-05 10:55:49 +01:00
3 changed files with 74 additions and 18 deletions

View File

@@ -463,9 +463,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);
}
T result = errorFunction.apply(exMono);
return insertCheckpoint(result, response.statusCode(), request);
}

View File

@@ -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) {