Document exception wrapping in RestClient status handlers
This commit documents the fact that any (Unchecked)IOExceptions or HttpMessageNotReadableExceptions thrown from the error handler will be wrapped in a RestClientException. Closes gh-31783
This commit is contained in:
@@ -592,6 +592,27 @@ class RestClientIntegrationTests {
|
||||
expectRequest(request -> assertThat(request.getPath()).isEqualTo("/greeting"));
|
||||
}
|
||||
|
||||
@ParameterizedRestClientTest
|
||||
void statusHandlerIOException(ClientHttpRequestFactory requestFactory) {
|
||||
startServer(requestFactory);
|
||||
|
||||
prepareResponse(response -> response.setResponseCode(500)
|
||||
.setHeader("Content-Type", "text/plain").setBody("Internal Server error"));
|
||||
|
||||
assertThatExceptionOfType(RestClientException.class).isThrownBy(() ->
|
||||
this.restClient.get()
|
||||
.uri("/greeting")
|
||||
.retrieve()
|
||||
.onStatus(HttpStatusCode::is5xxServerError, (request, response) -> {
|
||||
throw new IOException("500 error!");
|
||||
})
|
||||
.body(String.class)
|
||||
).withCauseInstanceOf(IOException.class);
|
||||
|
||||
expectRequestCount(1);
|
||||
expectRequest(request -> assertThat(request.getPath()).isEqualTo("/greeting"));
|
||||
}
|
||||
|
||||
@ParameterizedRestClientTest
|
||||
void statusHandlerParameterizedTypeReference(ClientHttpRequestFactory requestFactory) {
|
||||
startServer(requestFactory);
|
||||
|
||||
Reference in New Issue
Block a user