Add createException to ConvertibleClientHttpResponse

Closes gh-35391
This commit is contained in:
rstoyanchev
2025-08-29 16:04:45 +03:00
parent 21e6d7392d
commit f22d1eab23
3 changed files with 24 additions and 1 deletions
@@ -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();