Package org.springframework.web.server
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:
- HandlerMethodValidationException,- MethodNotAllowedException,- 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 SummaryNested classes/interfaces inherited from interface org.springframework.web.ErrorResponseErrorResponse.Builder, ErrorResponse.Interceptor
- 
Constructor SummaryConstructorsModifierConstructorDescriptionResponseStatusException(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 SummaryModifier 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 org.springframework.web.ErrorResponseExceptiongetBody, getDetailMessageArguments, getDetailMessageCode, getStatusCode, setDetail, setInstance, setTitle, setTypeMethods inherited from class org.springframework.core.NestedRuntimeExceptioncontains, getMostSpecificCause, getRootCauseMethods inherited from class java.lang.ThrowableaddSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toStringMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.springframework.web.ErrorResponsegetDetailMessageArguments, getTitleMessageCode, getTypeMessageCode
- 
Constructor Details- 
ResponseStatusExceptionConstructor with a response status.- Parameters:
- status- the HTTP status (required)
 
- 
ResponseStatusExceptionConstructor 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)
 
- 
ResponseStatusExceptionpublic 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
 
- 
ResponseStatusExceptionpublic 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)
 
- 
ResponseStatusExceptionprotected 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- 
getReasonThe reason explaining the exception (potentiallynullor empty).
- 
getHeadersReturn headers to add to the error response, for example, "Allow", "Accept", etc.- Specified by:
- getHeadersin interface- ErrorResponse
- Overrides:
- getHeadersin class- ErrorResponseException
 
- 
updateAndGetBodyDescription 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- the- MessageSourceto use for the lookup
- locale- the- Localeto use for the lookup
 
- 
getMessage- Overrides:
- getMessagein class- ErrorResponseException
 
 
-