ProblemDetail body. Allows any
exception to expose HTTP error response information.
ErrorResponseException is a default implementation of this
interface and a convenient base class for other exceptions to use.
ErrorResponse is supported as a return value from
@ExceptionHandler methods that render directly to the response, e.g.
by being marked @ResponseBody, or declared in an
@RestController or RestControllerAdvice class.
ErrorResponseException
| Modifier and Type | Class and Description |
|---|---|
| public static interface | ErrorResponse.Builder
Builder for an |
| Modifier and Type | Method and Description |
|---|---|
| public static ErrorResponse. | builder(Throwable
the underlying exception that lead to the error response;
mainly to derive default values for the
detail message code and for the
title message code. ex, HttpStatusCode the status code to set in the response statusCode, String the default value for the
detail)detail field, unless overridden
by a MessageSource lookup with getDetailMessageCode()Return a builder to create an |
| public static ErrorResponse. | builder(Throwable ex, ProblemDetail problemDetail)
Variant of |
| public static ErrorResponse | create(Throwable ex, HttpStatusCode statusCode, String detail)
Static factory method to build an instance via
|
| public ProblemDetail | getBody()
Return the body for the response, formatted as an RFC 7807
|
| public static String | getDefaultDetailMessageCode(Class<?>
the exception type associated with the problem exceptionType, String an optional suffix, e.g. for exceptions that may have multiple
error message with different arguments suffix)Build a message code for the "detail" field, for the given exception type. |
| public static String | getDefaultTitleMessageCode(Class<?>
the exception type associated with the problem exceptionType)Build a message code for the "title" field, for the given exception type. |
| public static String | getDefaultTypeMessageCode(Class<?>
the exception type associated with the problem exceptionType)Build a message code for the "type" field, for the given exception type. |
| public default Object[] | getDetailMessageArguments()
Return arguments to use along with a |
| public default Object[] | getDetailMessageArguments(MessageSource
the messageSource, Locale MessageSource to use for the lookupthe locale)Locale to use for the lookupVariant of |
| public default String | getDetailMessageCode()
Return a code to use to resolve the problem "detail" for this exception
through a |
| public default HttpHeaders | |
| public HttpStatusCode | |
| public default String | getTitleMessageCode()
Return a code to use to resolve the problem "title" for this exception
through a |
| public default String | getTypeMessageCode()
Return a code to use to resolve the problem "type" for this exception
through a |
| public default ProblemDetail | updateAndGetBody(MessageSource
the messageSource, Locale MessageSource to use for the lookupthe locale)Locale to use for the lookupUse the given |
| builder | back to summary |
|---|---|
| public static ErrorResponse. Return a builder to create an
| |
| builder | back to summary |
|---|---|
| public static ErrorResponse. Variant of
| |
| create | back to summary |
|---|---|
| public static ErrorResponse create(Throwable ex, HttpStatusCode statusCode, String detail) Static factory method to build an instance via
| |
| getBody | back to summary |
|---|---|
| public ProblemDetail getBody() Return the body for the response, formatted as an RFC 7807
| |
| getDefaultDetailMessageCode | back to summary |
|---|---|
| public static String getDefaultDetailMessageCode(Class<?> exceptionType, String suffix) Build a message code for the "detail" field, for the given exception type.
| |
| getDefaultTitleMessageCode | back to summary |
|---|---|
| public static String getDefaultTitleMessageCode(Class<?> exceptionType) Build a message code for the "title" field, for the given exception type.
| |
| getDefaultTypeMessageCode | back to summary |
|---|---|
| public static String getDefaultTypeMessageCode(Class<?> exceptionType) Build a message code for the "type" field, for the given exception type.
| |
| getDetailMessageArguments | back to summary |
|---|---|
| public default Object[] getDetailMessageArguments() Return arguments to use along with a
| |
| getDetailMessageArguments | back to summary |
|---|---|
| public default Object[] getDetailMessageArguments(MessageSource messageSource, Locale locale) Variant of This is useful for example to expand message codes from validation errors. The default implementation delegates to
| |
| getDetailMessageCode | back to summary |
|---|---|
| public default String getDetailMessageCode() Return a code to use to resolve the problem "detail" for this exception
through a By default this is initialized via
| |
| getHeaders | back to summary |
|---|---|
| public default HttpHeaders getHeaders() Return headers to use for the response. | |
| getStatusCode | back to summary |
|---|---|
| public HttpStatusCode getStatusCode() Return the HTTP status code to use for the response. | |
| getTitleMessageCode | back to summary |
|---|---|
| public default String getTitleMessageCode() Return a code to use to resolve the problem "title" for this exception
through a By default this is initialized via | |
| getTypeMessageCode | back to summary |
|---|---|
| public default String getTypeMessageCode() Return a code to use to resolve the problem "type" for this exception
through a By default this is initialized via
| |
| updateAndGetBody | back to summary |
|---|---|
| public default ProblemDetail updateAndGetBody(MessageSource messageSource, Locale locale) Use the given
| |
ErrorResponse.
| Modifier and Type | Method and Description |
|---|---|
| public ErrorResponse | |
| public default ErrorResponse | build(MessageSource messageSource, Locale locale)
Build the |
| public ErrorResponse. | |
| public ErrorResponse. | Returns: the same builder instancethe arguments to provide messageArguments)Set the arguments to provide to the |
| public ErrorResponse. | Returns: the same builder instancethe message code to use messageCode)Customize the |
| public ErrorResponse. | |
| public ErrorResponse. | Returns: the same builder instancea function that consumes the headersConsumer)HttpHeadersManipulate this response's headers with the given consumer. |
| public ErrorResponse. | |
| public ErrorResponse. | |
| public ErrorResponse. | |
| public ErrorResponse. | Returns: the same builder instancethe message code to use messageCode)Customize the |
| public ErrorResponse. | |
| public ErrorResponse. | Returns: the same builder instancethe message code to use messageCode)Customize the |
| build | back to summary |
|---|---|
| public ErrorResponse build() Build the | |
| build | back to summary |
|---|---|
| public default ErrorResponse build(MessageSource messageSource, Locale locale) Build the
| |
| detail | back to summary |
|---|---|
| public ErrorResponse. Set the underlying
| |
| detailMessageArguments | back to summary |
|---|---|
| public ErrorResponse. Set the arguments to provide to the
| |
| detailMessageCode | back to summary |
|---|---|
| public ErrorResponse. Customize the By default, set from
| |
| header | back to summary |
|---|---|
| public ErrorResponse. Add the given header value(s) under the given name.
| |
| headers | back to summary |
|---|---|
| public ErrorResponse. Manipulate this response's headers with the given consumer. This is
useful to overwrite or
remove existing values, or
use any other
| |
| instance | back to summary |
|---|---|
| public ErrorResponse. Set the underlying
| |
| property | back to summary |
|---|---|
| public ErrorResponse. Set a "dynamic"
| |
| title | back to summary |
|---|---|
| public ErrorResponse. Set the underlying
| |
| titleMessageCode | back to summary |
|---|---|
| public ErrorResponse. Customize the By default, set from
| |
| type | back to summary |
|---|---|
| public ErrorResponse. Set the underlying
| |
| typeMessageCode | back to summary |
|---|---|
| public ErrorResponse. Customize the By default, set from
| |