mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-23 06:29:10 +00:00
Add createException to ConvertibleClientHttpResponse
Closes gh-35391
This commit is contained in:
@@ -961,6 +961,11 @@ final class DefaultRestClient implements RestClient {
|
||||
Class<T> bodyClass = bodyClass(type);
|
||||
return readWithMessageConverters(this.delegate, () -> {}, type, bodyClass, this.hints);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RestClientResponseException createException() throws IOException {
|
||||
return StatusHandler.createException(this, DefaultRestClient.this.messageConverters);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -878,6 +878,15 @@ public interface RestClient {
|
||||
* @return the body, or {@code null} if no response body was available
|
||||
*/
|
||||
<T> @Nullable T bodyTo(ParameterizedTypeReference<T> bodyType);
|
||||
|
||||
/**
|
||||
* Create a {@link RestClientResponseException} of the appropriate
|
||||
* subtype depending on the response status code. The exception contains
|
||||
* the status, headers, and body of the response.
|
||||
* @throws IOException in case of a response failure (e.g. to obtain the status)
|
||||
* @since 7.0
|
||||
*/
|
||||
RestClientResponseException createException() throws IOException;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -108,7 +108,16 @@ final class StatusHandler {
|
||||
});
|
||||
}
|
||||
|
||||
private static RestClientResponseException createException(
|
||||
/**
|
||||
* Create a {@link RestClientResponseException} of the appropriate
|
||||
* subtype depending on the response status code.
|
||||
* @param response the response
|
||||
* @param converters the converters to use to decode the body
|
||||
* @return the created exception
|
||||
* @throws IOException in case of a response failure (e.g. to obtain the status)
|
||||
* @since 7.0
|
||||
*/
|
||||
public static RestClientResponseException createException(
|
||||
ClientHttpResponse response, List<HttpMessageConverter<?>> converters) throws IOException {
|
||||
|
||||
HttpStatusCode statusCode = response.getStatusCode();
|
||||
|
||||
Reference in New Issue
Block a user