ResponseErrorHandler that uses HttpMessageConverters to convert HTTP error responses to RestClientExceptions.
To use this error handler, you must specify a
status mapping and/or a
series mapping. If either of these mappings has a match
for the status code of a given
ClientHttpResponse, hasError(ClientHttpResponse) will return
true, and handleError(ClientHttpResponse) will attempt to use the
configured message converters to convert the response
into the mapped subclass of RestClientException. Note that the
status mapping takes precedence over
series mapping.
If there is no match, this error handler will default to the behavior of
DefaultResponseErrorHandler. Note that you can override this default behavior
by specifying a series mapping from
HttpStatus.Series#CLIENT_ERROR and/or HttpStatus.Series#SERVER_ERROR
to null.
RestTemplate#setErrorHandler(ResponseErrorHandler)
| Modifier and Type | Field and Description |
|---|---|
| private List | |
| private final Map | |
| private final Map |
| Access | Constructor and Description |
|---|---|
| public | |
| public | ExtractingResponseErrorHandler(List<HttpMessageConverter<?>>
the message converters to use messageConverters)Create a new |
| Modifier and Type | Method and Description |
|---|---|
| private void | |
| public void | handleError(ClientHttpResponse response, HttpStatusCode statusCode)
Overrides org. |
| protected boolean | hasError(HttpStatusCode
the HTTP status code statusCode)Overrides org. hasError(ClientHttpResponse).
|
| public void | setMessageConverters(List<HttpMessageConverter<?>> messageConverters)
Overrides org. |
| public void | setSeriesMapping(Map<HttpStatus.
Set the mapping from HTTP status series to |
| public void | setStatusMapping(Map<HttpStatusCode, Class<? extends RestClientException>> statusMapping)
Set the mapping from HTTP status code to |
| messageConverters | back to summary |
|---|---|
| private List<HttpMessageConverter<?>> messageConverters Hides org. | |
| seriesMapping | back to summary |
|---|---|
| private final Map<HttpStatus. | |
| statusMapping | back to summary |
|---|---|
| private final Map<HttpStatusCode, Class<? extends RestClientException>> statusMapping | |
| ExtractingResponseErrorHandler | back to summary |
|---|---|
| public ExtractingResponseErrorHandler() Create a new, empty Note that | |
| ExtractingResponseErrorHandler | back to summary |
|---|---|
| public ExtractingResponseErrorHandler(List<HttpMessageConverter<?>> messageConverters) Create a new
| |
| extract | back to summary |
|---|---|
| private void extract(Class<? extends RestClientException> exceptionClass, ClientHttpResponse response) throws IOException | |
| handleError | back to summary |
|---|---|
| public void handleError(ClientHttpResponse response, HttpStatusCode statusCode) throws IOException Overrides org. Doc from org. Handle the error based on the resolved status code. The default implementation delegates to
| |
| hasError | back to summary |
|---|---|
| protected boolean hasError(HttpStatusCode statusCode) Overrides org. Doc from org. Template method called from The default implementation checks
| |
| setMessageConverters | back to summary |
|---|---|
| public void setMessageConverters(List<HttpMessageConverter<?>> messageConverters) Overrides org. Set the message converters to use by this extractor.
| |
| setSeriesMapping | back to summary |
|---|---|
| public void setSeriesMapping(Map<HttpStatus. Set the mapping from HTTP status series to | |
| setStatusMapping | back to summary |
|---|---|
| public void setStatusMapping(Map<HttpStatusCode, Class<? extends RestClientException>> statusMapping) Set the mapping from HTTP status code to | |