Package org.springframework.web

# Class ErrorResponseException

java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
org.springframework.core.NestedRuntimeException
org.springframework.web.ErrorResponseException

All Implemented Interfaces:
  `Serializable`, `ErrorResponse`

Direct Known Subclasses:
  `ResponseStatusException`

public class ErrorResponseException extends org.springframework.core.NestedRuntimeException implements ErrorResponse
`RuntimeException` that implements `ErrorResponse` to expose an HTTP status, response headers, and a body formatted as an RFC 9457 `ProblemDetail`.

The exception can be used as is, or it can be extended as a more specific exception that populates the `type` or `detail` fields, or potentially adds other non-standard properties.

Since:
  6.0
Author:
  Rossen Stoyanchev
See Also:
  - Serialized Form

## Nested Class Summary

## Nested classes/interfaces inherited from interface org.springframework.web.ErrorResponse

`ErrorResponse.Builder, ErrorResponse.Interceptor`

## Constructor Summary

Constructors
Constructor
Description
`ErrorResponseException(HttpStatusCode status)`
Constructor with an `HttpStatusCode`.
`ErrorResponseException(HttpStatusCode status, Throwable cause)`
Constructor with an `HttpStatusCode` and an optional cause.
`ErrorResponseException(HttpStatusCode status, ProblemDetail body, Throwable cause)`
Constructor with a given `ProblemDetail` instance, possibly a subclass of `ProblemDetail` with extended fields.
`ErrorResponseException(HttpStatusCode status, ProblemDetail body, Throwable cause, String messageDetailCode, Object[] messageDetailArguments)`
Constructor with a given `ProblemDetail`, and a `MessageSource` code and arguments to resolve the detail message with.

## Method Summary

Modifier and Type
Method
Description
`final ProblemDetail`
`getBody()`
Return the body for the response.
`Object[]`
`getDetailMessageArguments()`
Return arguments to use along with a `message code` to resolve the problem "detail" for this exception through a `MessageSource`.
`String`
`getDetailMessageCode()`
Return a code to use to resolve the problem "detail" for this exception through a `MessageSource`.
`HttpHeaders`
`getHeaders()`
Return headers to use for the response.
`String`
`getMessage()`
`HttpStatusCode`
`getStatusCode()`
Return the HTTP status code to use for the response.
`void`
`setDetail(String detail)`
Set the `detail` field of the response body.
`void`
`setInstance(URI instance)`
Set the `instance` field of the response body.
`void`
`setTitle(String title)`
Set the `title` field of the response body.
`void`
`setType(URI type)`
Set the `type` field of the response body.

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

`contains, 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`

### Methods inherited from interface org.springframework.web.ErrorResponse

`getDetailMessageArguments, getTitleMessageCode, getTypeMessageCode, updateAndGetBody`

## Constructor Details

### ErrorResponseException

public ErrorResponseException(HttpStatusCode status)
Constructor with an `HttpStatusCode`.

### ErrorResponseException

public ErrorResponseException(HttpStatusCode status, @Nullable Throwable cause)
Constructor with an `HttpStatusCode` and an optional cause.

### ErrorResponseException

public ErrorResponseException(HttpStatusCode status, ProblemDetail body, @Nullable Throwable cause)
Constructor with a given `ProblemDetail` instance, possibly a subclass of `ProblemDetail` with extended fields.

### ErrorResponseException

public ErrorResponseException(HttpStatusCode status, ProblemDetail body, @Nullable Throwable cause, @Nullable String messageDetailCode, @Nullable Object[] messageDetailArguments)
Constructor with a given `ProblemDetail`, and a `MessageSource` code and arguments to resolve the detail message with.

Since:
  6.0

## Method Details

### getStatusCode

public HttpStatusCode getStatusCode()
Description copied from interface: `ErrorResponse`
Return the HTTP status code to use for the response.

Specified by:
  `getStatusCode` in interface `ErrorResponse`

### getHeaders

public HttpHeaders getHeaders()
Description copied from interface: `ErrorResponse`
Return headers to use for the response.

Specified by:
  `getHeaders` in interface `ErrorResponse`

### setType

public void setType(URI type)
Set the `type` field of the response body.

Parameters:
  `type` - the problem type

### setTitle

public void setTitle(@Nullable String title)
Set the `title` field of the response body.

Parameters:
  `title` - the problem title

### setDetail

public void setDetail(@Nullable String detail)
Set the `detail` field of the response body.

Parameters:
  `detail` - the problem detail

### setInstance

public void setInstance(@Nullable URI instance)
Set the `instance` field of the response body.

Parameters:
  `instance` - the problem instance

### getBody

public final ProblemDetail getBody()
Return the body for the response. To customize the body content, use:

- `setType(URI)`
- `setTitle(String)`
- `setDetail(String)`
- `setInstance(URI)`

By default, the status field of `ProblemDetail` is initialized from the status provided to the constructor, which in turn may also initialize the title field from the status reason phrase, if the status is well-known. The instance field, if not set, is initialized from the request path when a `ProblemDetail` is returned from an `@ExceptionHandler` method.

Specified by:
  `getBody` in interface `ErrorResponse`

### getDetailMessageCode

public String getDetailMessageCode()
Description copied from interface: `ErrorResponse`
Return a code to use to resolve the problem "detail" for this exception through a `MessageSource`.

By default this is initialized via `ErrorResponse.getDefaultDetailMessageCode(Class, String)`.

Specified by:
  `getDetailMessageCode` in interface `ErrorResponse`

### getDetailMessageArguments

@Nullable public Object[] getDetailMessageArguments()
Description copied from interface: `ErrorResponse`
Return arguments to use along with a `message code` to resolve the problem "detail" for this exception through a `MessageSource`. The arguments are expanded into placeholders of the message value, for example, "Invalid content type {0}".

Specified by:
  `getDetailMessageArguments` in interface `ErrorResponse`

### getMessage

public String getMessage()

Overrides:
  `getMessage` in class `Throwable`