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:
ContentTooLargeException, HandlerMethodValidationException, InvalidApiVersionException, MethodNotAllowedException, MissingApiVersionException, NoResourceFoundException, NotAcceptableStatusException, PayloadTooLargeException, ServerErrorException, ServerWebInputException, UnsupportedMediaTypeStatusException
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:
-
Nested Class Summary
Nested classes/interfaces inherited from interface ErrorResponse
ErrorResponse.Builder, ErrorResponse.Interceptor -
Constructor Summary
ConstructorsModifierConstructorDescriptionResponseStatusException(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.Constructor with a response status.ResponseStatusException(HttpStatusCode status, @Nullable String reason) Constructor with a response status and a reason to add to the exception message as explanation.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.protectedResponseStatusException(HttpStatusCode status, @Nullable String reason, @Nullable Throwable cause, @Nullable String messageDetailCode, Object @Nullable [] messageDetailArguments) Constructor with a message code and arguments for resolving the error "detail" viaMessageSource. -
Method Summary
Modifier and TypeMethodDescriptionReturn headers to add to the error response, for example, "Allow", "Accept", etc.The reason explaining the exception (potentiallynullor empty).updateAndGetBody(@Nullable MessageSource messageSource, Locale locale) Use the givenMessageSourceto resolve thetype,title, anddetailmessage codes, and then use the resolved values to update the corresponding fields inErrorResponse.getBody().Methods inherited from class ErrorResponseException
getBody, getDetailMessageArguments, getDetailMessageCode, getStatusCode, setDetail, setInstance, setTitle, setTypeMethods inherited from class NestedRuntimeException
contains, getMostSpecificCause, getRootCauseMethods inherited from class Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toStringMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface ErrorResponse
getDetailMessageArguments, getTitleMessageCode, getTypeMessageCode
-
Constructor Details
-
ResponseStatusException
Constructor with a response status.- Parameters:
status- the HTTP status (required)
-
ResponseStatusException
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 valuereason- 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, Object @Nullable [] messageDetailArguments) Constructor with a message code and arguments for resolving the error "detail" viaMessageSource.- Parameters:
status- the HTTP status (required)reason- the associated reason (optional)cause- a nested exception (optional)- Since:
- 6.0
-
-
Method Details
-
getReason
-
getHeaders
Return headers to add to the error response, for example, "Allow", "Accept", etc.- Specified by:
getHeadersin interfaceErrorResponse- Overrides:
getHeadersin classErrorResponseException
-
updateAndGetBody
Description copied from interface:ErrorResponseUse the givenMessageSourceto resolve thetype,title, anddetailmessage codes, and then use the resolved values to update the corresponding fields inErrorResponse.getBody().- Parameters:
messageSource- theMessageSourceto use for the lookuplocale- theLocaleto use for the lookup
-
getMessage
- Overrides:
getMessagein classErrorResponseException
-