spring-framework / org.springframework.web.client / ExtractingResponseErrorHandler

ExtractingResponseErrorHandler

open class ExtractingResponseErrorHandler : DefaultResponseErrorHandler

Implementation of ResponseErrorHandler that uses HttpMessageConverters to convert HTTP error responses to RestClientException.

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.

Author
Simon Galperin

Author
Arjen Poutsma

Since
5.0

See Also
RestTemplate#setErrorHandler(ResponseErrorHandler)

Constructors

<init>

ExtractingResponseErrorHandler()

Create a new, empty ExtractingResponseErrorHandler.

Note that #setMessageConverters(List) must be called when using this constructor.

ExtractingResponseErrorHandler(messageConverters: MutableList<HttpMessageConverter<*>>)

Create a new ExtractingResponseErrorHandler with the given HttpMessageConverter instances.

Functions

handleError

open fun handleError(response: ClientHttpResponse, statusCode: HttpStatus): Unit

setMessageConverters

open fun setMessageConverters(messageConverters: MutableList<HttpMessageConverter<*>>): Unit

Set the message converters to use by this extractor.

setSeriesMapping

open fun setSeriesMapping(seriesMapping: MutableMap<Series, Class<out RestClientException>>): Unit

Set the mapping from HTTP status series to RestClientException subclass. If this mapping 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.

setStatusMapping

open fun setStatusMapping(statusMapping: MutableMap<HttpStatus, Class<out RestClientException>>): Unit

Set the mapping from HTTP status code to RestClientException subclass. If this mapping 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.