Package org.springframework.web.client
Class RestClientResponseException
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
org.springframework.core.NestedRuntimeException
org.springframework.web.client.RestClientException
org.springframework.web.client.RestClientResponseException
- All Implemented Interfaces:
- Serializable
- Direct Known Subclasses:
- HttpStatusCodeException,- UnknownHttpStatusCodeException
Common base class for exceptions that contain actual HTTP response data.
- Since:
- 4.3
- Author:
- Rossen Stoyanchev
- See Also:
- 
Constructor SummaryConstructorsConstructorDescriptionRestClientResponseException(String message, int statusCode, String statusText, HttpHeaders headers, byte[] responseBody, Charset responseCharset) Construct a new instance of with the given response data.RestClientResponseException(String message, HttpStatusCode statusCode, String statusText, HttpHeaders headers, byte[] responseBody, Charset responseCharset) Construct a new instance of with the given response data.
- 
Method SummaryModifier and TypeMethodDescriptionintDeprecated.<E> EgetResponseBodyAs(Class<E> targetType) Convert the error response content to the specified type.<E> EgetResponseBodyAs(ParameterizedTypeReference<E> targetType) Variant ofgetResponseBodyAs(Class)withParameterizedTypeReference.byte[]Return the response body as a byte array.Return the response body converted to String.getResponseBodyAsString(Charset fallbackCharset) Return the response body converted to String.Return the HTTP response headers.Return the HTTP status code.Return the HTTP status text.voidsetBodyConvertFunction(Function<ResolvableType, ?> bodyConvertFunction) Provide a function to use to decode the response error content viagetResponseBodyAs(Class).Methods inherited from class org.springframework.core.NestedRuntimeExceptioncontains, getMostSpecificCause, getRootCauseMethods inherited from class java.lang.ThrowableaddSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
- 
Constructor Details- 
RestClientResponseExceptionpublic RestClientResponseException(String message, int statusCode, String statusText, @Nullable HttpHeaders headers, @Nullable byte[] responseBody, @Nullable Charset responseCharset) Construct a new instance of with the given response data.- Parameters:
- statusCode- the raw status code value
- statusText- the status text
- headers- the response headers (may be- null)
- responseBody- the response body content (may be- null)
- responseCharset- the response body charset (may be- null)
 
- 
RestClientResponseExceptionpublic RestClientResponseException(String message, HttpStatusCode statusCode, String statusText, @Nullable HttpHeaders headers, @Nullable byte[] responseBody, @Nullable Charset responseCharset) Construct a new instance of with the given response data.- Parameters:
- statusCode- the raw status code value
- statusText- the status text
- headers- the response headers (may be- null)
- responseBody- the response body content (may be- null)
- responseCharset- the response body charset (may be- null)
- Since:
- 6.0
 
 
- 
- 
Method Details- 
getStatusCodeReturn the HTTP status code.- Since:
- 6.0
 
- 
getRawStatusCodeDeprecated.as of 6.0, in favor ofgetStatusCode()Return the raw HTTP status code value.
- 
getStatusTextReturn the HTTP status text.
- 
getResponseHeadersReturn the HTTP response headers.
- 
getResponseBodyAsByteArraypublic byte[] getResponseBodyAsByteArray()Return the response body as a byte array.
- 
getResponseBodyAsStringReturn the response body converted to String. The charset used is that of the response "Content-Type" or otherwise"UTF-8".
- 
getResponseBodyAsStringReturn the response body converted to String. The charset used is that of the response "Content-Type" or otherwise the one given.- Parameters:
- fallbackCharset- the charset to use on if the response doesn't specify.
- Since:
- 5.1.11
 
- 
getResponseBodyAsConvert the error response content to the specified type.- Type Parameters:
- E- the expected target type
- Parameters:
- targetType- the type to convert to
- Returns:
- the converted object, or nullif there is no content
- Since:
- 6.0
 
- 
getResponseBodyAsVariant ofgetResponseBodyAs(Class)withParameterizedTypeReference.- Since:
- 6.0
 
- 
setBodyConvertFunctionProvide a function to use to decode the response error content viagetResponseBodyAs(Class).- Parameters:
- bodyConvertFunction- the function to use
- Since:
- 6.0
 
 
- 
getStatusCode()