Class ErrorResponseException

All Implemented Interfaces:
Serializable, ErrorResponse
Direct Known Subclasses:
ResponseStatusException

public class ErrorResponseException extends NestedRuntimeException implements ErrorResponse
RuntimeException that implements ErrorResponse to expose an HTTP status, response headers, and a body formatted as an RFC 7808 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:
  • Constructor Details

  • 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:

      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
    • getMessage

      public String getMessage()
      Overrides:
      getMessage in class Throwable