Class DefaultResponseErrorHandler
- All Implemented Interfaces:
ResponseErrorHandler
- Direct Known Subclasses:
ExtractingResponseErrorHandler
ResponseErrorHandler interface.
This error handler checks for the status code on the
ClientHttpResponse. Any code in the 4xx or 5xx series is considered
to be an error. This behavior can be changed by overriding
hasError(HttpStatusCode). Unknown status codes will be ignored by
hasError(ClientHttpResponse).
See handleError(URI, HttpMethod, ClientHttpResponse) for more
details on specific exception types.
- Since:
- 3.0
- Author:
- Arjen Poutsma, Rossen Stoyanchev, Juergen Hoeller
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionDeprecated, for removal: This API element is subject to removal in a future version. -
Method Summary
Modifier and TypeMethodDescriptiongetCharset(ClientHttpResponse response) Deprecated, for removal: This API element is subject to removal in a future version.Determine the charset of the response (for inclusion in a status exception).protected byte[]getResponseBody(ClientHttpResponse response) Deprecated, for removal: This API element is subject to removal in a future version.Read the body of the given response (for inclusion in a status exception).voidhandleError(URI url, HttpMethod method, ClientHttpResponse response) Deprecated, for removal: This API element is subject to removal in a future version.Handle the error in the given response with the given resolved status code and extra information providing access to the request URL and HTTP method.protected voidhandleError(ClientHttpResponse response, HttpStatusCode statusCode, @Nullable URI url, @Nullable HttpMethod method) Deprecated, for removal: This API element is subject to removal in a future version.Handle the error based on the resolved status code.booleanhasError(ClientHttpResponse response) Deprecated, for removal: This API element is subject to removal in a future version.Delegates tohasError(HttpStatusCode)with the response status code.protected booleanhasError(HttpStatusCode statusCode) Deprecated, for removal: This API element is subject to removal in a future version.Template method called fromhasError(ClientHttpResponse).protected Function<ResolvableType, ?> initBodyConvertFunction(ClientHttpResponse response, byte[] body) Deprecated, for removal: This API element is subject to removal in a future version.Return a function for decoding the error content.protected voidsetMessageConverters(List<HttpMessageConverter<?>> converters) Deprecated, for removal: This API element is subject to removal in a future version.For internal use from the RestTemplate, to pass the message converters to use to decode error content.
-
Constructor Details
-
DefaultResponseErrorHandler
public DefaultResponseErrorHandler()Deprecated, for removal: This API element is subject to removal in a future version.
-
-
Method Details
-
setMessageConverters
Deprecated, for removal: This API element is subject to removal in a future version.For internal use from the RestTemplate, to pass the message converters to use to decode error content.- Since:
- 6.0
-
hasError
Deprecated, for removal: This API element is subject to removal in a future version.Delegates tohasError(HttpStatusCode)with the response status code.- Specified by:
hasErrorin interfaceResponseErrorHandler- Parameters:
response- the response to inspect- Returns:
trueif the response indicates an error;falseotherwise- Throws:
IOException- in case of I/O errors- See Also:
-
hasError
Deprecated, for removal: This API element is subject to removal in a future version.Template method called fromhasError(ClientHttpResponse).The default implementation checks
HttpStatusCode.isError(). Can be overridden in subclasses.- Parameters:
statusCode- the HTTP status code- Returns:
trueif the response indicates an error;falseotherwise- See Also:
-
handleError
Deprecated, for removal: This API element is subject to removal in a future version.Handle the error in the given response with the given resolved status code and extra information providing access to the request URL and HTTP method.The default implementation throws:
HttpClientErrorExceptionif the status code is in the 4xx series, or one of its sub-classes such asHttpClientErrorException.BadRequestand others.HttpServerErrorExceptionif the status code is in the 5xx series, or one of its sub-classes such asHttpServerErrorException.InternalServerErrorand others.UnknownHttpStatusCodeExceptionfor error status codes not in theHttpStatusenum range.
- Specified by:
handleErrorin interfaceResponseErrorHandler- Parameters:
url- the request URLmethod- the HTTP methodresponse- the response with the error- Throws:
UnknownHttpStatusCodeException- in case of an unresolvable status codeIOException- in case of I/O errors- Since:
- 6.2
- See Also:
-
handleError
protected void handleError(ClientHttpResponse response, HttpStatusCode statusCode, @Nullable URI url, @Nullable HttpMethod method) throws IOException Deprecated, for removal: This API element is subject to removal in a future version.Handle the error based on the resolved status code.The default implementation delegates to
HttpClientErrorException.create(HttpStatusCode, String, HttpHeaders, byte[], Charset)for errors in the 4xx range, toHttpServerErrorException.create(HttpStatusCode, String, HttpHeaders, byte[], Charset)for errors in the 5xx range, or otherwise raisesUnknownHttpStatusCodeException.- Throws:
IOException- Since:
- 6.2
- See Also:
-
getResponseBody
Deprecated, for removal: This API element is subject to removal in a future version.Read the body of the given response (for inclusion in a status exception).- Parameters:
response- the response to inspect- Returns:
- the response body as a byte array, or an empty byte array if the body could not be read
- Since:
- 4.3.8
-
getCharset
Deprecated, for removal: This API element is subject to removal in a future version.Determine the charset of the response (for inclusion in a status exception).- Parameters:
response- the response to inspect- Returns:
- the associated charset, or
nullif none - Since:
- 4.3.8
-
initBodyConvertFunction
protected Function<ResolvableType, ?> initBodyConvertFunction(ClientHttpResponse response, byte[] body) Deprecated, for removal: This API element is subject to removal in a future version.Return a function for decoding the error content. This can be passed toRestClientResponseException.setBodyConvertFunction(Function).- Since:
- 6.0
-
RestClient.ResponseSpec.ErrorHandler