Package org.springframework.web.client

# Class HttpClientErrorException

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
org.springframework.web.client.HttpStatusCodeException
org.springframework.web.client.HttpClientErrorException

All Implemented Interfaces:
  `Serializable`

Direct Known Subclasses:
  `HttpClientErrorException.BadRequest`, `HttpClientErrorException.Conflict`, `HttpClientErrorException.Forbidden`, `HttpClientErrorException.Gone`, `HttpClientErrorException.MethodNotAllowed`, `HttpClientErrorException.NotAcceptable`, `HttpClientErrorException.NotFound`, `HttpClientErrorException.TooManyRequests`, `HttpClientErrorException.Unauthorized`, `HttpClientErrorException.UnprocessableEntity`, `HttpClientErrorException.UnsupportedMediaType`

public class HttpClientErrorException extends HttpStatusCodeException
Exception thrown when an HTTP 4xx is received.

Since:
  3.0
Author:
  Arjen Poutsma
See Also:
  - `DefaultResponseErrorHandler`
  - Serialized Form

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`static final class`
`HttpClientErrorException.BadRequest`
`HttpClientErrorException` for status HTTP 400 Bad Request.
`static final class`
`HttpClientErrorException.Conflict`
`HttpClientErrorException` for status HTTP 409 Conflict.
`static final class`
`HttpClientErrorException.Forbidden`
`HttpClientErrorException` for status HTTP 403 Forbidden.
`static final class`
`HttpClientErrorException.Gone`
`HttpClientErrorException` for status HTTP 410 Gone.
`static final class`
`HttpClientErrorException.MethodNotAllowed`
`HttpClientErrorException` for status HTTP 405 Method Not Allowed.
`static final class`
`HttpClientErrorException.NotAcceptable`
`HttpClientErrorException` for status HTTP 406 Not Acceptable.
`static final class`
`HttpClientErrorException.NotFound`
`HttpClientErrorException` for status HTTP 404 Not Found.
`static final class`
`HttpClientErrorException.TooManyRequests`
`HttpClientErrorException` for status HTTP 429 Too Many Requests.
`static final class`
`HttpClientErrorException.Unauthorized`
`HttpClientErrorException` for status HTTP 401 Unauthorized.
`static final class`
`HttpClientErrorException.UnprocessableEntity`
`HttpClientErrorException` for status HTTP 422 Unprocessable Entity.
`static final class`
`HttpClientErrorException.UnsupportedMediaType`
`HttpClientErrorException` for status HTTP 415 Unsupported Media Type.

## Constructor Summary

Constructors
Constructor
Description
`HttpClientErrorException(String message, HttpStatusCode statusCode, String statusText, HttpHeaders headers, byte[] body, Charset responseCharset)`
Constructor with a status code and status text, headers, and content, and a prepared message.
`HttpClientErrorException(HttpStatusCode statusCode)`
Constructor with a status code only.
`HttpClientErrorException(HttpStatusCode statusCode, String statusText)`
Constructor with a status code and status text.
`HttpClientErrorException(HttpStatusCode statusCode, String statusText, byte[] body, Charset responseCharset)`
Constructor with a status code and status text, and content.
`HttpClientErrorException(HttpStatusCode statusCode, String statusText, HttpHeaders headers, byte[] body, Charset responseCharset)`
Constructor with a status code and status text, headers, and content.

## Method Summary

Modifier and Type
Method
Description
`static HttpClientErrorException`
`create(String message, HttpStatusCode statusCode, String statusText, HttpHeaders headers, byte[] body, Charset charset)`
Variant of `create(HttpStatusCode, String, HttpHeaders, byte[], Charset)` with an optional prepared message.
`static HttpClientErrorException`
`create(HttpStatusCode statusCode, String statusText, HttpHeaders headers, byte[] body, Charset charset)`
Create `HttpClientErrorException` or an HTTP status specific subclass.

### Methods inherited from class org.springframework.web.client.RestClientResponseException

`getRawStatusCode, getResponseBodyAs, getResponseBodyAs, getResponseBodyAsByteArray, getResponseBodyAsString, getResponseBodyAsString, getResponseHeaders, getStatusCode, getStatusText, setBodyConvertFunction`

### Methods inherited from class org.springframework.core.NestedRuntimeException

`contains, getMostSpecificCause, getRootCause`

### Methods inherited from class java.lang.Throwable

`addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, 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 Details

### HttpClientErrorException

public HttpClientErrorException(HttpStatusCode statusCode)
Constructor with a status code only.

### HttpClientErrorException

public HttpClientErrorException(HttpStatusCode statusCode, String statusText)
Constructor with a status code and status text.

### HttpClientErrorException

public HttpClientErrorException(HttpStatusCode statusCode, String statusText, @Nullable byte[] body, @Nullable Charset responseCharset)
Constructor with a status code and status text, and content.

### HttpClientErrorException

public HttpClientErrorException(HttpStatusCode statusCode, String statusText, @Nullable HttpHeaders headers, @Nullable byte[] body, @Nullable Charset responseCharset)
Constructor with a status code and status text, headers, and content.

### HttpClientErrorException

public HttpClientErrorException(String message, HttpStatusCode statusCode, String statusText, @Nullable HttpHeaders headers, @Nullable byte[] body, @Nullable Charset responseCharset)
Constructor with a status code and status text, headers, and content, and a prepared message.

Since:
  5.2.2

## Method Details

### create

public static HttpClientErrorException create(HttpStatusCode statusCode, String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset)
Create `HttpClientErrorException` or an HTTP status specific subclass.

Since:
  5.1

### create

public static HttpClientErrorException create(@Nullable String message, HttpStatusCode statusCode, String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset)
Variant of `create(HttpStatusCode, String, HttpHeaders, byte[], Charset)` with an optional prepared message.

Since:
  5.2.2