Skip to content

Commit

Permalink
Disable "failOnServerError" in ReactorClientHttpRequest
Browse files Browse the repository at this point in the history
This commit disables the "failOnServerError" feature on the
`HttpClientRequest`, as wrapped by ReactorClientHttpRequest. 5xx errors
are supposed to be dealt with in the WebClient, not in the lower-level
components.

Issue: SPR-15739
  • Loading branch information
poutsma committed Jul 6, 2017
1 parent 0065bc5 commit b0ab846
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 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.
Expand Down Expand Up @@ -53,7 +53,7 @@ public ReactorClientHttpRequest(HttpMethod httpMethod, URI uri,
HttpClientRequest httpRequest) {
this.httpMethod = httpMethod;
this.uri = uri;
this.httpRequest = httpRequest.failOnClientError(false);
this.httpRequest = httpRequest.failOnClientError(false).failOnServerError(false);
this.bufferFactory = new NettyDataBufferFactory(httpRequest.alloc());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,26 @@ public void retrieveBodyToMonoNotFound() throws Exception {
Assert.assertEquals("/greeting?name=Spring", recordedRequest.getPath());
}

@Test
public void retrieveBodyToMonoInternalServerError() throws Exception {
this.server.enqueue(new MockResponse().setResponseCode(500)
.setHeader("Content-Type", "text/plain").setBody("Internal Server error"));

Mono<String> result = this.webClient.get()
.uri("/greeting?name=Spring")
.retrieve()
.bodyToMono(String.class);

StepVerifier.create(result)
.expectError(WebClientException.class)
.verify(Duration.ofSeconds(3));

RecordedRequest recordedRequest = server.takeRequest();
Assert.assertEquals(1, server.getRequestCount());
Assert.assertEquals("*/*", recordedRequest.getHeader(HttpHeaders.ACCEPT));
Assert.assertEquals("/greeting?name=Spring", recordedRequest.getPath());
}

@Test
public void retrieveToEntityNotFound() throws Exception {
this.server.enqueue(new MockResponse().setResponseCode(404)
Expand Down

0 comments on commit b0ab846

Please sign in to comment.