Browse Source

Add createException to ConvertibleClientHttpResponse

Closes gh-35391
pull/35397/head
rstoyanchev 5 months ago
parent
commit
f22d1eab23
  1. 5
      spring-web/src/main/java/org/springframework/web/client/DefaultRestClient.java
  2. 9
      spring-web/src/main/java/org/springframework/web/client/RestClient.java
  3. 11
      spring-web/src/main/java/org/springframework/web/client/StatusHandler.java

5
spring-web/src/main/java/org/springframework/web/client/DefaultRestClient.java

@ -961,6 +961,11 @@ final class DefaultRestClient implements RestClient { @@ -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);
}
}
}

9
spring-web/src/main/java/org/springframework/web/client/RestClient.java

@ -878,6 +878,15 @@ public interface RestClient { @@ -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;
}
}

11
spring-web/src/main/java/org/springframework/web/client/StatusHandler.java

@ -108,7 +108,16 @@ final class StatusHandler { @@ -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();

Loading…
Cancel
Save