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

      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, e.g. "Invalid content type {0}".
      Specified by:
      getDetailMessageArguments in interface ErrorResponse
    • getMessage

      public String getMessage()
      Overrides:
      getMessage in class Throwable