类 DefaultResponseErrorHandler
- java.lang.Object
- org.springframework.web.client.DefaultResponseErrorHandler
- 所有已实现的接口:
ResponseErrorHandler
public class DefaultResponseErrorHandler extends Object implements ResponseErrorHandler
Spring's default implementation of theResponseErrorHandler
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 overridinghasError(HttpStatus)
. Unknown status codes will be ignored byhasError(ClientHttpResponse)
.See
handleError(ClientHttpResponse)
for more details on specific exception types.- 从以下版本开始:
- 3.0
- 作者:
- Arjen Poutsma, Rossen Stoyanchev, Juergen Hoeller
- 另请参阅:
RestTemplate.setErrorHandler(org.springframework.web.client.ResponseErrorHandler)
构造器概要
构造器 构造器 说明 DefaultResponseErrorHandler()
方法概要
所有方法 实例方法 具体方法 已过时的方法 修饰符和类型 方法 说明 protected Charset
getCharset(ClientHttpResponse response)
Determine the charset of the response (for inclusion in a status exception).protected HttpStatus
getHttpStatusCode(ClientHttpResponse response)
已过时。as of 5.0, in favor ofhandleError(ClientHttpResponse, HttpStatus)
protected byte[]
getResponseBody(ClientHttpResponse response)
Read the body of the given response (for inclusion in a status exception).void
handleError(ClientHttpResponse response)
Handle the error in the given response with the given resolved status code.protected void
handleError(ClientHttpResponse response, HttpStatus statusCode)
Handle the error based on the resolved status code.protected boolean
hasError(int unknownStatusCode)
Template method called fromhasError(ClientHttpResponse)
.boolean
hasError(ClientHttpResponse response)
Delegates tohasError(HttpStatus)
(for a standard status enum value) orhasError(int)
(for an unknown status code) with the response status code.protected boolean
hasError(HttpStatus statusCode)
Template method called fromhasError(ClientHttpResponse)
.从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
从接口继承的方法 org.springframework.web.client.ResponseErrorHandler
handleError
构造器详细资料
DefaultResponseErrorHandler
public DefaultResponseErrorHandler()
方法详细资料
hasError
public boolean hasError(ClientHttpResponse response) throws IOException
Delegates tohasError(HttpStatus)
(for a standard status enum value) orhasError(int)
(for an unknown status code) with the response status code.- 指定者:
hasError
在接口中ResponseErrorHandler
- 参数:
response
- the response to inspect- 返回:
true
if the response indicates an error;false
otherwise- 抛出:
IOException
- in case of I/O errors- 另请参阅:
ClientHttpResponse.getRawStatusCode()
,hasError(HttpStatus)
,hasError(int)
hasError
protected boolean hasError(HttpStatus statusCode)
Template method called fromhasError(ClientHttpResponse)
.The default implementation checks
HttpStatus.isError()
. Can be overridden in subclasses.- 参数:
statusCode
- the HTTP status code as enum value- 返回:
true
if the response indicates an error;false
otherwise- 另请参阅:
HttpStatus.isError()
hasError
protected boolean hasError(int unknownStatusCode)
Template method called fromhasError(ClientHttpResponse)
.The default implementation checks if the given status code is
CLIENT_ERROR
orSERVER_ERROR
. Can be overridden in subclasses.- 参数:
unknownStatusCode
- the HTTP status code as raw value- 返回:
true
if the response indicates an error;false
otherwise- 从以下版本开始:
- 4.3.21
- 另请参阅:
HttpStatus.Series.CLIENT_ERROR
,HttpStatus.Series.SERVER_ERROR
handleError
public void handleError(ClientHttpResponse response) throws IOException
Handle the error in the given response with the given resolved status code.The default implementation throws:
HttpClientErrorException
if the status code is in the 4xx series, or one of its sub-classes such asHttpClientErrorException.BadRequest
and others.HttpServerErrorException
if the status code is in the 5xx series, or one of its sub-classes such asHttpServerErrorException.InternalServerError
and others.UnknownHttpStatusCodeException
for error status codes not in theHttpStatus
enum range.
- 指定者:
handleError
在接口中ResponseErrorHandler
- 参数:
response
- the response with the error- 抛出:
UnknownHttpStatusCodeException
- in case of an unresolvable status codeIOException
- in case of I/O errors- 另请参阅:
handleError(ClientHttpResponse, HttpStatus)
handleError
protected void handleError(ClientHttpResponse response, HttpStatus statusCode) throws IOException
Handle the error based on the resolved status code.The default implementation delegates to
HttpClientErrorException.create(org.springframework.http.HttpStatus, java.lang.String, org.springframework.http.HttpHeaders, byte[], java.nio.charset.Charset)
for errors in the 4xx range, toHttpServerErrorException.create(org.springframework.http.HttpStatus, java.lang.String, org.springframework.http.HttpHeaders, byte[], java.nio.charset.Charset)
for errors in the 5xx range, or otherwise raisesUnknownHttpStatusCodeException
.- 抛出:
IOException
- 从以下版本开始:
- 5.0
- 另请参阅:
HttpClientErrorException.create(org.springframework.http.HttpStatus, java.lang.String, org.springframework.http.HttpHeaders, byte[], java.nio.charset.Charset)
,HttpServerErrorException.create(org.springframework.http.HttpStatus, java.lang.String, org.springframework.http.HttpHeaders, byte[], java.nio.charset.Charset)
getHttpStatusCode
@Deprecated protected HttpStatus getHttpStatusCode(ClientHttpResponse response) throws IOException
已过时。as of 5.0, in favor ofhandleError(ClientHttpResponse, HttpStatus)
Determine the HTTP status of the given response.- 参数:
response
- the response to inspect- 返回:
- the associated HTTP status
- 抛出:
IOException
- in case of I/O errorsUnknownHttpStatusCodeException
- in case of an unknown status code that cannot be represented with theHttpStatus
enum- 从以下版本开始:
- 4.3.8
getResponseBody
protected byte[] getResponseBody(ClientHttpResponse response)
Read the body of the given response (for inclusion in a status exception).- 参数:
response
- the response to inspect- 返回:
- the response body as a byte array, or an empty byte array if the body could not be read
- 从以下版本开始:
- 4.3.8
getCharset
@Nullable protected Charset getCharset(ClientHttpResponse response)
Determine the charset of the response (for inclusion in a status exception).- 参数:
response
- the response to inspect- 返回:
- the associated charset, or
null
if none - 从以下版本开始:
- 4.3.8