Package org.springframework.web.server

# Class ResponseStatusException

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

All Implemented Interfaces:
  `Serializable`, `ErrorResponse`

Direct Known Subclasses:
  `HandlerMethodValidationException`, `MethodNotAllowedException`, `NotAcceptableStatusException`, `PayloadTooLargeException`, `ServerErrorException`, `ServerWebInputException`, `UnsupportedMediaTypeStatusException`

public class ResponseStatusException extends ErrorResponseException
Subclass of `ErrorResponseException` that accepts a "reason", and by default maps that to the `"detail"` of the `ProblemDetail`.

Since:
  5.0
Author:
  Rossen Stoyanchev, Juergen Hoeller
See Also:
  - Serialized Form

## Nested Class Summary

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

`ErrorResponse.Builder, ErrorResponse.Interceptor`

## Constructor Summary

Constructors
Modifier
Constructor
Description
``
`ResponseStatusException(int rawStatusCode, String reason, Throwable cause)`
Constructor with a response status and a reason to add to the exception message as explanation, as well as a nested exception.
``
`ResponseStatusException(HttpStatusCode status)`
Constructor with a response status.
``
`ResponseStatusException(HttpStatusCode status, String reason)`
Constructor with a response status and a reason to add to the exception message as explanation.
``
`ResponseStatusException(HttpStatusCode status, String reason, Throwable cause)`
Constructor with a response status and a reason to add to the exception message as explanation, as well as a nested exception.
`protected`
`ResponseStatusException(HttpStatusCode status, String reason, Throwable cause, String messageDetailCode, Object[] messageDetailArguments)`
Constructor with a message code and arguments for resolving the error "detail" via `MessageSource`.

## Method Summary

Modifier and Type
Method
Description
`HttpHeaders`
`getHeaders()`
Return headers to add to the error response, for example, "Allow", "Accept", etc.
`String`
`getMessage()`
`String`
`getReason()`
The reason explaining the exception (potentially `null` or empty).
`HttpHeaders`
`getResponseHeaders()`
Deprecated.
as of 6.0 in favor of `getHeaders()`
`ProblemDetail`
`updateAndGetBody(org.springframework.context.MessageSource messageSource, Locale locale)`
Use the given `MessageSource` to resolve the `type`, `title`, and `detail` message codes, and then use the resolved values to update the corresponding fields in `ErrorResponse.getBody()`.

### Methods inherited from class org.springframework.web.ErrorResponseException

`getBody, getDetailMessageArguments, getDetailMessageCode, getStatusCode, setDetail, setInstance, setTitle, setType`

### 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`

## Constructor Details

### ResponseStatusException

public ResponseStatusException(HttpStatusCode status)
Constructor with a response status.

Parameters:
  `status` - the HTTP status (required)

### ResponseStatusException

public ResponseStatusException(HttpStatusCode status, @Nullable String reason)
Constructor with a response status and a reason to add to the exception message as explanation.

Parameters:
  `status` - the HTTP status (required)
  `reason` - the associated reason (optional)

### ResponseStatusException

public ResponseStatusException(int rawStatusCode, @Nullable String reason, @Nullable Throwable cause)
Constructor with a response status and a reason to add to the exception message as explanation, as well as a nested exception.

Parameters:
  `rawStatusCode` - the HTTP status code value
  `reason` - the associated reason (optional)
  `cause` - a nested exception (optional)
Since:
  5.3

### ResponseStatusException

public ResponseStatusException(HttpStatusCode status, @Nullable String reason, @Nullable Throwable cause)
Constructor with a response status and a reason to add to the exception message as explanation, as well as a nested exception.

Parameters:
  `status` - the HTTP status (required)
  `reason` - the associated reason (optional)
  `cause` - a nested exception (optional)

### ResponseStatusException

protected ResponseStatusException(HttpStatusCode status, @Nullable String reason, @Nullable Throwable cause, @Nullable String messageDetailCode, @Nullable Object[] messageDetailArguments)
Constructor with a message code and arguments for resolving the error "detail" via `MessageSource`.

Parameters:
  `status` - the HTTP status (required)
  `reason` - the associated reason (optional)
  `cause` - a nested exception (optional)
Since:
  6.0

## Method Details

### getReason

@Nullable public String getReason()
The reason explaining the exception (potentially `null` or empty).

### getHeaders

public HttpHeaders getHeaders()
Return headers to add to the error response, for example, "Allow", "Accept", etc.

By default, delegates to `getResponseHeaders()` for backwards compatibility.

Specified by:
  `getHeaders` in interface `ErrorResponse`
Overrides:
  `getHeaders` in class `ErrorResponseException`

### getResponseHeaders

@Deprecated(since="6.0") public HttpHeaders getResponseHeaders()
Deprecated.
as of 6.0 in favor of `getHeaders()`
Return headers associated with the exception that should be added to the error response, for example, "Allow", "Accept", etc.

The default implementation in this class returns empty headers.

Since:
  5.1.13

### updateAndGetBody

public ProblemDetail updateAndGetBody(@Nullable org.springframework.context.MessageSource messageSource, Locale locale)
Description copied from interface: `ErrorResponse`
Use the given `MessageSource` to resolve the `type`, `title`, and `detail` message codes, and then use the resolved values to update the corresponding fields in `ErrorResponse.getBody()`.

Parameters:
  `messageSource` - the `MessageSource` to use for the lookup
  `locale` - the `Locale` to use for the lookup

### getMessage

public String getMessage()

Overrides:
  `getMessage` in class `ErrorResponseException`