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
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:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.springframework.web.ErrorResponse
ErrorResponse.Builder
-
Constructor Summary
ConstructorDescriptionErrorResponseException
(HttpStatusCode status) Constructor with anHttpStatusCode
.ErrorResponseException
(HttpStatusCode status, Throwable cause) Constructor with anHttpStatusCode
and an optional cause.ErrorResponseException
(HttpStatusCode status, ProblemDetail body, Throwable cause) Constructor with a givenProblemDetail
instance, possibly a subclass ofProblemDetail
with extended fields.ErrorResponseException
(HttpStatusCode status, ProblemDetail body, Throwable cause, String messageDetailCode, Object[] messageDetailArguments) Constructor with a givenProblemDetail
, and aMessageSource
code and arguments to resolve the detail message with. -
Method Summary
Modifier and TypeMethodDescriptionfinal ProblemDetail
getBody()
Return the body for the response.Object[]
Return arguments to use along with amessage code
to resolve the problem "detail" for this exception through aMessageSource
.Return a code to use to resolve the problem "detail" for this exception through aMessageSource
.Return headers to use for the response.Return the HTTP status code to use for the response.void
Set thedetail
field of the response body.void
setInstance
(URI instance) Set theinstance
field of the response body.void
Set thetitle
field of the response body.void
Set thetype
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
Constructor with anHttpStatusCode
. -
ErrorResponseException
Constructor with anHttpStatusCode
and an optional cause. -
ErrorResponseException
Constructor with a givenProblemDetail
instance, possibly a subclass ofProblemDetail
with extended fields. -
ErrorResponseException
public ErrorResponseException(HttpStatusCode status, ProblemDetail body, @Nullable Throwable cause, @Nullable String messageDetailCode, @Nullable Object[] messageDetailArguments) Constructor with a givenProblemDetail
, and aMessageSource
code and arguments to resolve the detail message with.- Since:
- 6.0
-
-
Method Details
-
getStatusCode
Description copied from interface:ErrorResponse
Return the HTTP status code to use for the response.- Specified by:
getStatusCode
in interfaceErrorResponse
-
getHeaders
Description copied from interface:ErrorResponse
Return headers to use for the response.- Specified by:
getHeaders
in interfaceErrorResponse
-
setType
Set thetype
field of the response body.- Parameters:
type
- the problem type
-
setTitle
Set thetitle
field of the response body.- Parameters:
title
- the problem title
-
setDetail
Set thedetail
field of the response body.- Parameters:
detail
- the problem detail
-
setInstance
Set theinstance
field of the response body.- Parameters:
instance
- the problem instance
-
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 aProblemDetail
is returned from an@ExceptionHandler
method.- Specified by:
getBody
in interfaceErrorResponse
-
getDetailMessageCode
Description copied from interface:ErrorResponse
Return a code to use to resolve the problem "detail" for this exception through aMessageSource
.By default this is initialized via
ErrorResponse.getDefaultDetailMessageCode(Class, String)
.- Specified by:
getDetailMessageCode
in interfaceErrorResponse
-
getDetailMessageArguments
Description copied from interface:ErrorResponse
Return arguments to use along with amessage code
to resolve the problem "detail" for this exception through aMessageSource
. The arguments are expanded into placeholders of the message value, e.g. "Invalid content type {0}".- Specified by:
getDetailMessageArguments
in interfaceErrorResponse
-
getMessage
- Overrides:
getMessage
in classThrowable
-