Top Description Fields Constructors Methods
org.springframework.web

public Class ErrorResponseException

extends NestedRuntimeException
implements ErrorResponse
Class Inheritance
All Implemented Interfaces
org.springframework.web.ErrorResponse
Known Direct Subclasses
org.springframework.web.server.ResponseStatusException
Annotations
@SuppressWarnings:serial
Imports
java.net.URI, org.springframework.core.NestedRuntimeException, org.springframework.http.HttpHeaders, .HttpStatusCode, .ProblemDetail, org.springframework.lang.Nullable

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.

Author
Rossen Stoyanchev
Since
6.0

Field Summary

Modifier and TypeField and Description
private final ProblemDetail
private final HttpHeaders
private final Object[]
private final String
private final HttpStatusCode

Constructor Summary

AccessConstructor and Description
public
public
ErrorResponseException(HttpStatusCode status, Throwable cause)

Constructor with an HttpStatusCode and an optional cause.

public
ErrorResponseException(HttpStatusCode status, ProblemDetail body, Throwable cause)

Constructor with a given ProblemDetail instance, possibly a subclass of ProblemDetail with extended fields.

public
ErrorResponseException(HttpStatusCode status, ProblemDetail body, Throwable cause, String messageDetailCode, Object[] messageDetailArguments)

Constructor with a given ProblemDetail, and a org.springframework.context.MessageSource code and arguments to resolve the detail message with.

Method Summary

Modifier and TypeMethod and Description
public final ProblemDetail
getBody()

Implements org.springframework.web.ErrorResponse.getBody.

Return the body for the response.

public Object[]
getDetailMessageArguments()

Overrides default org.springframework.web.ErrorResponse.getDetailMessageArguments.

Return arguments to use along with a message code to resolve the problem "detail" for this exception through a MessageSource.

public String
getDetailMessageCode()

Overrides default org.springframework.web.ErrorResponse.getDetailMessageCode.

Return a code to use to resolve the problem "detail" for this exception through a MessageSource.

public HttpHeaders
getHeaders()

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

Return headers to use for the response.

public String
getMessage()

Overrides java.lang.Throwable.getMessage.

Returns the detail message string of this throwable.

public HttpStatusCode
getStatusCode()

Implements org.springframework.web.ErrorResponse.getStatusCode.

Return the HTTP status code to use for the response.

private String
initMessageDetailCode(String messageDetailCode)

public void
setDetail(String
the problem detail
detail
)

Set the detail field of the response body.

public void
setInstance(URI
the problem instance
instance
)

Set the instance field of the response body.

public void
setTitle(String
the problem title
title
)

Set the title field of the response body.

public void
setType(URI
the problem type
type
)

Set the type field of the response body.

Inherited from org.springframework.core.NestedRuntimeException:
containsgetMostSpecificCausegetRootCause

Field Detail

bodyback to summary
private final ProblemDetail body
headersback to summary
private final HttpHeaders headers
messageDetailArgumentsback to summary
private final Object[] messageDetailArguments
Annotations
@Nullable
messageDetailCodeback to summary
private final String messageDetailCode
statusback to summary
private final HttpStatusCode status

Constructor Detail

ErrorResponseExceptionback to summary
public ErrorResponseException(HttpStatusCode status)

Constructor with an HttpStatusCode.

ErrorResponseExceptionback to summary
public ErrorResponseException(HttpStatusCode status, Throwable cause)

Constructor with an HttpStatusCode and an optional cause.

ErrorResponseExceptionback to summary
public ErrorResponseException(HttpStatusCode status, ProblemDetail body, Throwable cause)

Constructor with a given ProblemDetail instance, possibly a subclass of ProblemDetail with extended fields.

ErrorResponseExceptionback to summary
public ErrorResponseException(HttpStatusCode status, ProblemDetail body, Throwable cause, String messageDetailCode, Object[] messageDetailArguments)

Constructor with a given ProblemDetail, and a org.springframework.context.MessageSource code and arguments to resolve the detail message with.

Since
6.0

Method Detail

getBodyback to summary
public final ProblemDetail getBody()

Implements org.springframework.web.ErrorResponse.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.

Annotations
@Override
getDetailMessageArgumentsback to summary
public Object[] getDetailMessageArguments()

Overrides default org.springframework.web.ErrorResponse.getDetailMessageArguments.

Doc from org.springframework.web.ErrorResponse.getDetailMessageArguments.

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}".

Annotations
@Override
getDetailMessageCodeback to summary
public String getDetailMessageCode()

Overrides default org.springframework.web.ErrorResponse.getDetailMessageCode.

Doc from org.springframework.web.ErrorResponse.getDetailMessageCode.

Return a code to use to resolve the problem "detail" for this exception through a MessageSource.

By default this is initialized via getDefaultDetailMessageCode(Class, String).

Annotations
@Override
getHeadersback to summary
public HttpHeaders getHeaders()

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

Doc from org.springframework.web.ErrorResponse.getHeaders.

Return headers to use for the response.

Annotations
@Override
getMessageback to summary
public String getMessage()

Overrides java.lang.Throwable.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
getStatusCodeback to summary
public HttpStatusCode getStatusCode()

Implements org.springframework.web.ErrorResponse.getStatusCode.

Doc from org.springframework.web.ErrorResponse.getStatusCode.

Return the HTTP status code to use for the response.

Annotations
@Override
initMessageDetailCodeback to summary
private String initMessageDetailCode(String messageDetailCode)
setDetailback to summary
public void setDetail(String detail)

Set the detail field of the response body.

Parameters
detail:String

the problem detail

setInstanceback to summary
public void setInstance(URI instance)

Set the instance field of the response body.

Parameters
instance:URI

the problem instance

setTitleback to summary
public void setTitle(String title)

Set the title field of the response body.

Parameters
title:String

the problem title

setTypeback to summary
public void setType(URI type)

Set the type field of the response body.

Parameters
type:URI

the problem type