Class ResponseStatusException

All Implemented Interfaces:
Serializable, ErrorResponse
Direct Known Subclasses:
MethodNotAllowedException, NotAcceptableStatusException, ServerErrorException, ServerWebInputException, UnsupportedMediaTypeStatusException

public class ResponseStatusException extends ErrorResponseException
Subclass of ErrorResponseException that accepts a "reason" and maps it to the "detail" property of ProblemDetail.
Since:
5.0
Author:
Rossen Stoyanchev, Juergen Hoeller
See Also:
  • Constructor Details

    • ResponseStatusException

      public ResponseStatusException(HttpStatus status)
      Constructor with a response status.
      Parameters:
      status - the HTTP status (required)
    • ResponseStatusException

      public ResponseStatusException(HttpStatus 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(HttpStatus 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

      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
  • 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, e.g. "Allow", "Accept", etc.

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

      Specified by:
      getHeaders in interface ErrorResponse
      Overrides:
      getHeaders in class ErrorResponseException
    • getResponseHeaders

      @Deprecated 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, e.g. "Allow", "Accept", etc.

      The default implementation in this class returns empty headers.

      Since:
      5.1.13
    • getMessage

      public String getMessage()
      Description copied from class: NestedRuntimeException
      Return the detail message, including the message from the nested exception if there is one.
      Overrides:
      getMessage in class ErrorResponseException