Class WebClientResponseException

java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
org.springframework.core.NestedRuntimeException
org.springframework.web.reactive.function.client.WebClientException
org.springframework.web.reactive.function.client.WebClientResponseException
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
UnknownHttpStatusCodeException, WebClientResponseException.BadGateway, WebClientResponseException.BadRequest, WebClientResponseException.Conflict, WebClientResponseException.Forbidden, WebClientResponseException.GatewayTimeout, WebClientResponseException.Gone, WebClientResponseException.InternalServerError, WebClientResponseException.MethodNotAllowed, WebClientResponseException.NotAcceptable, WebClientResponseException.NotFound, WebClientResponseException.NotImplemented, WebClientResponseException.ServiceUnavailable, WebClientResponseException.TooManyRequests, WebClientResponseException.Unauthorized, WebClientResponseException.UnprocessableEntity, WebClientResponseException.UnsupportedMediaType

public class WebClientResponseException extends WebClientException
Exceptions that contain actual HTTP response data.
Since:
5.0
Author:
Arjen Poutsma
See Also:
  • Constructor Details

    • WebClientResponseException

      public WebClientResponseException(int statusCode, String statusText, @Nullable org.springframework.http.HttpHeaders headers, @Nullable byte[] body, @Nullable Charset charset)
      Constructor with response data only, and a default message.
      Since:
      5.1
    • WebClientResponseException

      public WebClientResponseException(int status, String reasonPhrase, @Nullable org.springframework.http.HttpHeaders headers, @Nullable byte[] body, @Nullable Charset charset, @Nullable org.springframework.http.HttpRequest request)
      Constructor with response data only, and a default message.
      Since:
      5.1.4
    • WebClientResponseException

      public WebClientResponseException(org.springframework.http.HttpStatusCode statusCode, String reasonPhrase, @Nullable org.springframework.http.HttpHeaders headers, @Nullable byte[] body, @Nullable Charset charset, @Nullable org.springframework.http.HttpRequest request)
      Constructor with response data only, and a default message.
      Since:
      6.0
    • WebClientResponseException

      public WebClientResponseException(String message, int statusCode, String statusText, @Nullable org.springframework.http.HttpHeaders headers, @Nullable byte[] responseBody, @Nullable Charset charset)
      Constructor with a prepared message.
    • WebClientResponseException

      public WebClientResponseException(String message, int statusCode, String statusText, @Nullable org.springframework.http.HttpHeaders headers, @Nullable byte[] responseBody, @Nullable Charset charset, @Nullable org.springframework.http.HttpRequest request)
      Constructor with a prepared message.
      Since:
      5.1.4
    • WebClientResponseException

      public WebClientResponseException(String message, org.springframework.http.HttpStatusCode statusCode, String statusText, @Nullable org.springframework.http.HttpHeaders headers, @Nullable byte[] responseBody, @Nullable Charset charset, @Nullable org.springframework.http.HttpRequest request)
      Constructor with a prepared message.
      Since:
      6.0
  • Method Details

    • getStatusCode

      public org.springframework.http.HttpStatusCode getStatusCode()
      Return the HTTP status code value.
      Throws:
      IllegalArgumentException - in case of an unknown HTTP status code
    • getRawStatusCode

      @Deprecated(since="6.0") 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.
    • getHeaders

      public org.springframework.http.HttpHeaders getHeaders()
      Return the HTTP response headers.
    • getResponseBodyAsByteArray

      public byte[] getResponseBodyAsByteArray()
      Return the response body as a byte array.
    • getResponseBodyAsString

      public String getResponseBodyAsString()
      Return the response content as a String using the charset of media type for the response, if available, or otherwise falling back on ISO-8859-1. Use getResponseBodyAsString(Charset) if you want to fall back on a different, default charset.
    • getResponseBodyAsString

      public String getResponseBodyAsString(Charset defaultCharset)
      Variant of getResponseBodyAsString() that allows specifying the charset to fall back on, if a charset is not available from the media type for the response.
      Parameters:
      defaultCharset - the charset to use if the Content-Type of the response does not specify one.
      Since:
      5.3.7
    • getResponseBodyAs

      @Nullable public <E> E getResponseBodyAs(Class<E> targetType)
      Decode the error content to the specified type.
      Type Parameters:
      E - the expected target type
      Parameters:
      targetType - the type to decode to
      Returns:
      the decoded content, or null if there is no content
      Throws:
      IllegalStateException - if a Decoder cannot be found
      org.springframework.core.codec.DecodingException - if decoding fails
      Since:
      6.0
    • getResponseBodyAs

      @Nullable public <E> E getResponseBodyAs(org.springframework.core.ParameterizedTypeReference<E> targetType)
      Variant of getResponseBodyAs(Class) with ParameterizedTypeReference.
      Since:
      6.0
    • getRequest

      @Nullable public org.springframework.http.HttpRequest getRequest()
      Return the corresponding request.
      Since:
      5.1.4
    • setBodyDecodeFunction

      public void setBodyDecodeFunction(Function<org.springframework.core.ResolvableType,?> decoderFunction)
      Provide a function to find a decoder the given target type. For use with getResponseBodyAs(Class).
      Parameters:
      decoderFunction - the function to find a decoder with
      Since:
      6.0
    • create

      public static WebClientResponseException create(int statusCode, String statusText, org.springframework.http.HttpHeaders headers, byte[] body, @Nullable Charset charset)
      Create WebClientResponseException or an HTTP status specific subclass.
      Since:
      5.1
    • create

      public static WebClientResponseException create(int statusCode, String statusText, org.springframework.http.HttpHeaders headers, byte[] body, @Nullable Charset charset, @Nullable org.springframework.http.HttpRequest request)
      Create WebClientResponseException or an HTTP status specific subclass.
      Since:
      5.1.4
    • create

      public static WebClientResponseException create(org.springframework.http.HttpStatusCode statusCode, String statusText, org.springframework.http.HttpHeaders headers, byte[] body, @Nullable Charset charset, @Nullable org.springframework.http.HttpRequest request)
      Create WebClientResponseException or an HTTP status specific subclass.
      Since:
      6.0