Class 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:
  • Constructor Details

    • RestClientResponseException

      public 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)
    • RestClientResponseException

      public 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

    • getStatusCode

      public HttpStatusCode getStatusCode()
      Return the HTTP status code.
      Since:
      6.0
    • getRawStatusCode

      @Deprecated public int getRawStatusCode()
      Deprecated.
      as of 6.0, in favor of getStatusCode()
      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
    • getResponseBodyAs

      @Nullable public <E> E getResponseBodyAs(Class<E> targetType)
      Convert 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 null if there is no content
      Since:
      6.0
    • getResponseBodyAs

      @Nullable public <E> E getResponseBodyAs(ParameterizedTypeReference<E> targetType)
      Since:
      6.0
    • setBodyConvertFunction

      public void setBodyConvertFunction(Function<ResolvableType,?> bodyConvertFunction)
      Provide a function to use to decode the response error content via getResponseBodyAs(Class).
      Parameters:
      bodyConvertFunction - the function to use
      Since:
      6.0