Top Description Fields Constructors Methods
org.springframework.web.server

public Class ResponseStatusException

extends ErrorResponseException
Class Inheritance
Known Direct Subclasses
org.springframework.web.server.ServerErrorException, org.springframework.web.server.ServerWebInputException, org.springframework.web.server.UnsupportedMediaTypeStatusException, org.springframework.web.method.annotation.HandlerMethodValidationException, org.springframework.web.server.MethodNotAllowedException, org.springframework.web.server.NotAcceptableStatusException
Annotations
@SuppressWarnings:serial
Imports
java.util.Locale, org.springframework.context.MessageSource, org.springframework.http.HttpHeaders, .HttpStatusCode, .ProblemDetail, org.springframework.lang.Nullable, org.springframework.web.ErrorResponseException

Subclass of ErrorResponseException that accepts a "reason", and by default maps that to the "detail" of the ProblemDetail.
Authors
Rossen Stoyanchev, Juergen Hoeller
Since
5.0

Field Summary

Modifier and TypeField and Description
private final String

Constructor Summary

AccessConstructor and Description
public
ResponseStatusException(HttpStatusCode
the HTTP status (required)
status
)

Constructor with a response status.

public
ResponseStatusException(HttpStatusCode
the HTTP status (required)
status
,
String
the associated reason (optional)
reason
)

Constructor with a response status and a reason to add to the exception message as explanation.

public
ResponseStatusException(int
the HTTP status code value
rawStatusCode
,
String
the associated reason (optional)
reason
,
Throwable
a nested exception (optional)
cause
)

Constructor with a response status and a reason to add to the exception message as explanation, as well as a nested exception.

public
ResponseStatusException(HttpStatusCode
the HTTP status (required)
status
,
String
the associated reason (optional)
reason
,
Throwable
a nested exception (optional)
cause
)

Constructor with a response status and a reason to add to the exception message as explanation, as well as a nested exception.

protected
ResponseStatusException(HttpStatusCode
the HTTP status (required)
status
,
String
the associated reason (optional)
reason
,
Throwable
a nested exception (optional)
cause
,
String messageDetailCode, Object[] messageDetailArguments)

Constructor with a message code and arguments for resolving the error "detail" via org.springframework.context.MessageSource.

Method Summary

Modifier and TypeMethod and Description
public HttpHeaders
getHeaders()

Overrides org.springframework.web.ErrorResponseException.getHeaders.

Overrides default org.springframework.web.ErrorResponse.getHeaders.

Return headers to add to the error response, e.g. "Allow", "Accept", etc.

By default, delegates to getResponseHeaders() for backwards compatibility.

public String
getMessage()

Overrides org.springframework.web.ErrorResponseException.getMessage.

Returns the detail message string of this throwable.

public String
getReason()

The reason explaining the exception (potentially null or empty).

public HttpHeaders
getResponseHeaders()
Deprecated since 6.0. as of 6.0 in favor of getHeaders()

Return headers associated with the exception that should be added to the error response, e.g. "Allow", "Accept", etc.

The default implementation in this class returns empty headers.

public ProblemDetail
updateAndGetBody(MessageSource
the MessageSource to use for the lookup
messageSource
,
Locale
the Locale to use for the lookup
locale
)

Overrides default org.springframework.web.ErrorResponse.updateAndGetBody.

Use the given MessageSource to resolve the type, title, and detail message codes, and then use the resolved values to update the corresponding fields in getBody().

Inherited from org.springframework.web.ErrorResponseException:
getBodygetDetailMessageArgumentsgetDetailMessageCodegetStatusCodesetDetailsetInstancesetTitlesetType

Field Detail

reasonback to summary
private final String reason
Annotations
@Nullable

Constructor Detail

ResponseStatusExceptionback to summary
public ResponseStatusException(HttpStatusCode status)

Constructor with a response status.

Parameters
status:HttpStatusCode

the HTTP status (required)

ResponseStatusExceptionback to summary
public ResponseStatusException(HttpStatusCode status, String reason)

Constructor with a response status and a reason to add to the exception message as explanation.

Parameters
status:HttpStatusCode

the HTTP status (required)

reason:String

the associated reason (optional)

ResponseStatusExceptionback to summary
public ResponseStatusException(int rawStatusCode, String reason, 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:int

the HTTP status code value

reason:String

the associated reason (optional)

cause:Throwable

a nested exception (optional)

Since
5.3
ResponseStatusExceptionback to summary
public ResponseStatusException(HttpStatusCode status, String reason, 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:HttpStatusCode

the HTTP status (required)

reason:String

the associated reason (optional)

cause:Throwable

a nested exception (optional)

ResponseStatusExceptionback to summary
protected ResponseStatusException(HttpStatusCode status, String reason, Throwable cause, String messageDetailCode, Object[] messageDetailArguments)

Constructor with a message code and arguments for resolving the error "detail" via org.springframework.context.MessageSource.

Parameters
status:HttpStatusCode

the HTTP status (required)

reason:String

the associated reason (optional)

cause:Throwable

a nested exception (optional)

Since
6.0

Method Detail

getHeadersback to summary
public HttpHeaders getHeaders()

Overrides org.springframework.web.ErrorResponseException.getHeaders.

Overrides default org.springframework.web.ErrorResponse.getHeaders.

Return headers to add to the error response, e.g. "Allow", "Accept", etc.

By default, delegates to getResponseHeaders() for backwards compatibility.

Annotations
@Override
getMessageback to summary
public String getMessage()

Overrides org.springframework.web.ErrorResponseException.getMessage.

Doc from java.lang.Throwable.getMessage.

Returns the detail message string of this throwable.

Returns:String

the detail message string of this Throwable instance (which may be null).

Annotations
@Override
getReasonback to summary
public String getReason()

The reason explaining the exception (potentially null or empty).

Annotations
@Nullable
getResponseHeadersback to summary
public HttpHeaders getResponseHeaders()

Deprecated

since 6.0.

as of 6.0 in favor of getHeaders()

Return headers associated with the exception that should be added to the error response, e.g. "Allow", "Accept", etc.

The default implementation in this class returns empty headers.

Annotations
@Deprecated
since:6.0
Since
5.1.13
updateAndGetBodyback to summary
public ProblemDetail updateAndGetBody(MessageSource messageSource, Locale locale)

Overrides default org.springframework.web.ErrorResponse.updateAndGetBody.

Doc from org.springframework.web.ErrorResponse.updateAndGetBody.

Use the given MessageSource to resolve the type, title, and detail message codes, and then use the resolved values to update the corresponding fields in getBody().

Parameters
messageSource:MessageSource

the MessageSource to use for the lookup

locale:Locale

the Locale to use for the lookup

Annotations
@Override