org.springframework.web.client

## Class HttpStatusCodeException

- 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.HttpStatusCodeException

- All Implemented Interfaces:
    Serializable
  Direct Known Subclasses:
    HttpClientErrorException, HttpServerErrorException

      public abstract class HttpStatusCodeException
      extends RestClientException

  Abstract base class for exceptions based on an `HttpStatus`.
  Since:
    3.0
  Author:
    Arjen Poutsma, Chris Beams
  See Also:
    Serialized Form

- - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `HttpStatusCodeException(HttpStatus statusCode)` Construct a new instance of `HttpStatusCodeException` based on an `HttpStatus`.
    `protected` | `HttpStatusCodeException(HttpStatus statusCode, String statusText)` Construct a new instance of `HttpStatusCodeException` based on an `HttpStatus` and status text.
    `protected` | `HttpStatusCodeException(HttpStatus statusCode, String statusText, byte[] responseBody, Charset responseCharset)` Construct a new instance of `HttpStatusCodeException` based on an `HttpStatus`, status text, and response body content.
    `protected` | `HttpStatusCodeException(HttpStatus statusCode, String statusText, HttpHeaders responseHeaders, byte[] responseBody, Charset responseCharset)` Construct a new instance of `HttpStatusCodeException` based on an `HttpStatus`, status text, and response body content.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `byte[]` | `getResponseBodyAsByteArray()` Return the response body as a byte array.
    `String` | `getResponseBodyAsString()` Return the response body as a string.
    `HttpHeaders` | `getResponseHeaders()` Return the HTTP response headers.
    `HttpStatus` | `getStatusCode()` Return the HTTP status code.
    `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`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### HttpStatusCodeException

          protected HttpStatusCodeException(HttpStatus statusCode)

      Construct a new instance of `HttpStatusCodeException` based on an `HttpStatus`.
      Parameters:
        `statusCode` - the status code

    - #### HttpStatusCodeException

          protected HttpStatusCodeException(HttpStatus statusCode,
                                 String statusText)

      Construct a new instance of `HttpStatusCodeException` based on an `HttpStatus` and status text.
      Parameters:
        `statusCode` - the status code
        `statusText` - the status text

    - #### HttpStatusCodeException

          protected HttpStatusCodeException(HttpStatus statusCode,
                                 String statusText,
                                 byte[] responseBody,
                                 Charset responseCharset)

      Construct a new instance of `HttpStatusCodeException` based on an `HttpStatus`, status text, and response body content.
      Parameters:
        `statusCode` - the status code
        `statusText` - the status text
        `responseBody` - the response body content, may be `null`
        `responseCharset` - the response body charset, may be `null`
      Since:
        3.0.5

    - #### HttpStatusCodeException

          protected HttpStatusCodeException(HttpStatus statusCode,
                                 String statusText,
                                 HttpHeaders responseHeaders,
                                 byte[] responseBody,
                                 Charset responseCharset)

      Construct a new instance of `HttpStatusCodeException` based on an `HttpStatus`, status text, and response body content.
      Parameters:
        `statusCode` - the status code
        `statusText` - the status text
        `responseHeaders` - the response headers, may be `null`
        `responseBody` - the response body content, may be `null`
        `responseCharset` - the response body charset, may be `null`
      Since:
        3.1.2

  - ### Method Detail

    - #### getStatusCode

          public HttpStatus getStatusCode()

      Return the HTTP status code.

    - #### getStatusText

          public String getStatusText()

      Return the HTTP status text.

    - #### getResponseHeaders

          public HttpHeaders getResponseHeaders()

      Return the HTTP response headers.
      Since:
        3.1.2

    - #### getResponseBodyAsByteArray

          public byte[] getResponseBodyAsByteArray()

      Return the response body as a byte array.
      Since:
        3.0.5

    - #### getResponseBodyAsString

          public String getResponseBodyAsString()

      Return the response body as a string.
      Since:
        3.0.5