public class DefaultResponseErrorHandler extends java.lang.Object implements ResponseErrorHandler
ResponseErrorHandler
interface.
This error handler checks for the status code on the ClientHttpResponse
:
Any code with series HttpStatus.Series.CLIENT_ERROR
or HttpStatus.Series.SERVER_ERROR
is considered to be
an error; this behavior can be changed by overriding the hasError(HttpStatus)
method. Unknown status codes will be ignored by hasError(ClientHttpResponse)
.
RestTemplate.setErrorHandler(org.springframework.web.client.ResponseErrorHandler)
Constructor and Description |
---|
DefaultResponseErrorHandler() |
Modifier and Type | Method and Description |
---|---|
protected java.nio.charset.Charset |
getCharset(ClientHttpResponse response)
Determine the charset of the response (for inclusion in a status exception).
|
protected HttpStatus |
getHttpStatusCode(ClientHttpResponse response)
Deprecated.
as of 5.0, in favor of
handleError(ClientHttpResponse, HttpStatus) |
protected byte[] |
getResponseBody(ClientHttpResponse response)
Read the body of the given response (for inclusion in a status exception).
|
void |
handleError(ClientHttpResponse response)
Delegates to
handleError(ClientHttpResponse, HttpStatus) with the response status code. |
protected void |
handleError(ClientHttpResponse response,
HttpStatus statusCode)
Handle the error in the given response with the given resolved status code.
|
boolean |
hasError(ClientHttpResponse response)
Delegates to
hasError(HttpStatus) with the response status code. |
protected boolean |
hasError(HttpStatus statusCode)
Template method called from
hasError(ClientHttpResponse) . |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
handleError
public boolean hasError(ClientHttpResponse response) throws java.io.IOException
hasError(HttpStatus)
with the response status code.hasError
in interface ResponseErrorHandler
response
- the response to inspecttrue
if the response has an error; false
otherwisejava.io.IOException
- in case of I/O errorsprotected boolean hasError(HttpStatus statusCode)
hasError(ClientHttpResponse)
.
The default implementation checks if the given status code is
CLIENT_ERROR
or
SERVER_ERROR
.
Can be overridden in subclasses.
statusCode
- the HTTP status codetrue
if the response has an error; false
otherwisepublic void handleError(ClientHttpResponse response) throws java.io.IOException
handleError(ClientHttpResponse, HttpStatus)
with the response status code.handleError
in interface ResponseErrorHandler
response
- the response with the errorjava.io.IOException
- in case of I/O errorsprotected void handleError(ClientHttpResponse response, HttpStatus statusCode) throws java.io.IOException
This default implementation throws a HttpClientErrorException
if the response status code
is HttpStatus.Series.CLIENT_ERROR
, a HttpServerErrorException
if it is HttpStatus.Series.SERVER_ERROR
,
and a RestClientException
in other cases.
java.io.IOException
@Deprecated protected HttpStatus getHttpStatusCode(ClientHttpResponse response) throws java.io.IOException
handleError(ClientHttpResponse, HttpStatus)
response
- the response to inspectjava.io.IOException
- in case of I/O errorsUnknownHttpStatusCodeException
- in case of an unknown status code
that cannot be represented with the HttpStatus
enumprotected byte[] getResponseBody(ClientHttpResponse response)
response
- the response to inspect@Nullable protected java.nio.charset.Charset getCharset(ClientHttpResponse response)
response
- the response to inspectnull
if none