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
public class RestClientResponseException extends RestClientException
Common base class for exceptions that contain actual HTTP response data.- Since:
- 4.3
- Author:
- Rossen Stoyanchev
- See Also:
- Serialized Form
Constructor Summary
Constructors Constructor Description RestClientResponseException(String message, int statusCode, String statusText, HttpHeaders responseHeaders, byte[] responseBody, Charset responseCharset)
Construct a new instance of with the given response data.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
getRawStatusCode()
Return the raw HTTP status code value.byte[]
getResponseBodyAsByteArray()
Return the response body as a byte array.String
getResponseBodyAsString()
Return the response body converted to String.String
getResponseBodyAsString(Charset fallbackCharset)
Return the response body converted to String.HttpHeaders
getResponseHeaders()
Return the HTTP response headers.String
getStatusText()
Return the HTTP status text.Methods inherited from class org.springframework.core.NestedRuntimeException
contains, getMessage, getMostSpecificCause, getRootCause
Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
Constructor Detail
RestClientResponseException
public RestClientResponseException(String message, int statusCode, String statusText, @Nullable HttpHeaders responseHeaders, @Nullable byte[] responseBody, @Nullable Charset responseCharset)
Construct a new instance of with the given response data.- Parameters:
statusCode
- the raw status code valuestatusText
- the status textresponseHeaders
- the response headers (may benull
)responseBody
- the response body content (may benull
)responseCharset
- the response body charset (may benull
)
Method Detail
getRawStatusCode
public int getRawStatusCode()
Return the raw HTTP status code value.
getStatusText
public String getStatusText()
Return the HTTP status text.
getResponseHeaders
@Nullable public HttpHeaders getResponseHeaders()
Return the HTTP response headers.
getResponseBodyAsByteArray
public byte[] getResponseBodyAsByteArray()
Return the response body as a byte array.
getResponseBodyAsString
public String getResponseBodyAsString()
Return the response body converted to String. The charset used is that of the response "Content-Type" or otherwise"UTF-8"
.
getResponseBodyAsString
public String getResponseBodyAsString(Charset fallbackCharset)
Return 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