Exception Resolution Reference
Complete listing of what Problem4J Spring responds with for each Spring exception it handles out of the box, and for exceptions it knows nothing about. Use it to look up a particular response - for an introduction, see Exception Handling and Spring's Internal Exceptions.
All responses below are the defaults, before any of your customizations are applied:
titleis always derived fromstatus(e.g.400becomes"Bad Request"), unless stated otherwise.detailtexts are shown in the defaultcapitalizedformat. Withproblem4j.detail-formatset tolowercaseoruppercase, they become"validation failed"or"VALIDATION FAILED". Details copied from the exception itself (ErrorResponseException,@ResponseStatusreason) are never reformatted.ProblemPostProcessor(type,titleandinstanceoverrides) runs afterward, on every response listed here.- Every built-in resolver can be replaced by declaring your own
ProblemResolverbean for the same exception class (see ImplementingProblemResolver).
How an Exception Is Resolved
For an exception thrown from a controller, the first matching step wins:
ProblemException- its ownProblemis returned as is.- Exception class annotated with
@ProblemMapping- mapped from the annotation. - A
ProblemResolverregistered for the exception class, or for its closest superclass - see the tables below. - Exception class annotated with Spring's
@ResponseStatus- itscodebecomesstatusand its non-emptyreasonbecomesdetail. - Anything else - unknown exception, resolved as
500 Internal Server Error.
Spring's own exceptions that Spring Framework already assigns an HTTP status to (those handled by its
ResponseEntityExceptionHandler, such as NoResourceFoundException) go through step 3 as well. If no resolver
matches, they keep the status Spring assigned instead of falling back to 500.
Errors that never reach a controller (e.g. thrown by a servlet filter) are rendered by Spring Boot's error handling, which Problem4J replaces too. These carry only the status Spring Boot determined:
{
"status" : 404,
"title" : "Not Found"
}
The built-in resolvers are registered only if the exception class they handle is on the classpath, so WebMVC-only and WebFlux-only exceptions don't need to be told apart in your configuration.
Validation
| Exception | Status | detail | Extensions |
|---|---|---|---|
BindException, MethodArgumentNotValidException (WebMVC) | 400 | "Validation failed" | errors |
WebExchangeBindException (WebFlux) | 400 | "Validation failed" | errors |
HandlerMethodValidationException | 400 | "Validation failed" | errors |
HandlerMethodValidationException, for invalid return value | 500 | - | - |
MethodValidationException | 400 | "Validation failed" | errors |
jakarta.validation.ConstraintViolationException | 400 | "Validation failed" | errors |
errors lists every violation as field and error (the constraint message). For ConstraintViolationException,
field is the last element of the violation's property path.
{
"status" : 400,
"title" : "Bad Request",
"detail" : "Validation failed",
"errors" : [ {
"field" : "email",
"error" : "must be a well-formed email address"
} ]
}
See Validation Errors for how field names are resolved and customized.
Type Conversion and Request Body
| Exception | Status | detail | Extensions |
|---|---|---|---|
TypeMismatchException, MethodArgumentTypeMismatchException, ConversionNotSupportedException | 400 | "Type mismatch" | property, kind |
ServerWebInputException caused by TypeMismatchException (WebFlux) | 400 | "Type mismatch" | property, kind |
HttpMessageNotReadableException caused by a value of wrong type in JSON body | 400 | "Type mismatch" | property, kind |
DecodingException / ServerWebInputException caused by a value of wrong type in JSON body (WebFlux) | 400 | "Type mismatch" | property, kind |
HttpMessageNotReadableException, otherwise (e.g. malformed JSON) | 400 | - | - |
DecodingException, otherwise (WebFlux) | 400 | - | - |
ServerWebInputException, otherwise (WebFlux) | 400 | - | - |
propertyis the name of the parameter, or the dot-separated path of the JSON property (e.g."address.city"). In WebFlux, if Spring doesn't provide it, the name of the handler method parameter is used.kindis the expected type, as named by theTypeNameMapperbean. The defaultSimpleTypeNameMappernames integer types"integer", decimal types"number", and also knows"boolean","string","enum"and"array"(arrays and collections).kindis omitted for types the mapper doesn't name.- If the type mismatch in the JSON body can't be pinned to a property (e.g. the whole body has wrong type), the
response has no
detailand no extensions.
{
"status" : 400,
"title" : "Bad Request",
"detail" : "Type mismatch",
"property" : "age",
"kind" : "integer"
}
Missing Request Values
| Exception | Status | detail | Extensions |
|---|---|---|---|
MissingServletRequestParameterException (WebMVC) | 400 | "Missing request param" | param, kind |
MissingServletRequestPartException (WebMVC) | 400 | "Missing request part" | param |
MissingRequestHeaderException (WebMVC) | 400 | "Missing header" | header |
MissingRequestCookieException (WebMVC) | 400 | "Missing cookie" | cookie |
MissingPathVariableException (WebMVC) | 400 | "Missing path variable" | name |
ServletRequestBindingException for missing request attribute (WebMVC) | 400 | "Missing request attribute" | attribute |
ServletRequestBindingException for missing session attribute (WebMVC) | 400 | "Missing session attribute" | attribute |
ServletRequestBindingException, otherwise (WebMVC) | 400 | - | - |
MissingRequestValueException for query parameter (WebFlux) | 400 | "Missing request param" | param, kind |
MissingRequestValueException for request part (WebFlux) | 400 | "Missing request part" | param |
MissingRequestValueException for header (WebFlux) | 400 | "Missing header" | header |
MissingRequestValueException for cookie (WebFlux) | 400 | "Missing cookie" | cookie |
MissingRequestValueException for path variable (WebFlux) | 400 | "Missing path variable" | name |
MissingRequestValueException for request attribute (WebFlux) | 400 | "Missing request attribute" | attribute |
MissingRequestValueException for session attribute (WebFlux) | 400 | "Missing session attribute" | attribute |
ServerErrorException for missing @PathVariable (WebFlux) | 400 | "Missing path variable" | name |
Each extension holds the name of the missing value. kind of a missing request param is the lowercase simple name of
the parameter's Java type (e.g. "string", "long", "localdate") - unlike in
type conversion errors, it's not named by the TypeNameMapper.
{
"status" : 400,
"title" : "Bad Request",
"detail" : "Missing request param",
"param" : "page",
"kind" : "integer"
}
HTTP Protocol
| Exception | Status | detail | Extensions |
|---|---|---|---|
HttpRequestMethodNotSupportedException (WebMVC) | 405 | - | - |
MethodNotAllowedException (WebFlux) | 405 | - | - |
HttpMediaTypeNotAcceptableException (WebMVC) | 406 | - | - |
NotAcceptableStatusException (WebFlux) | 406 | - | - |
HttpMediaTypeNotSupportedException (WebMVC) | 415 | - | - |
UnsupportedMediaTypeStatusException (WebFlux) | 415 | - | - |
MaxUploadSizeExceededException (WebMVC) | 413 | "Max upload size exceeded" | max |
PayloadTooLargeException (WebFlux) | 413 | - | - |
MultipartException, otherwise (WebMVC) | 400 | - | - |
NoResourceFoundException, NoHandlerFoundException | 404 | - | - |
AsyncRequestTimeoutException (WebMVC) | 503 | - | - |
HttpMessageNotWritableException (WebMVC) | 500 | - | - |
max is the configured upload limit in bytes, included only if Spring knows it. Note that the reason phrase for 413
is Content Too Large, per RFC 9110 §15.5.14.
{
"status" : 413,
"title" : "Content Too Large",
"detail" : "Max upload size exceeded",
"max" : 1048576
}
For accessing unregistered paths, see also FAQ.
Spring's Generic Status Exceptions
| Exception | Status | detail | Extensions |
|---|---|---|---|
ErrorResponseException and its other subclasses | exception's status | from exception's ProblemDetail | from ProblemDetail properties |
ResponseStatusException and its other subclasses | exception's status | - | - |
ServerErrorException, otherwise (WebFlux) | 500 | - | - |
ErrorResponseExceptionis Spring's counterpart ofProblemException. ItsProblemDetailis copied whole -type,title,detail,instanceand all custom properties.ResponseStatusException(e.g.throw new ResponseStatusException(HttpStatus.GONE, "reason")) keeps only the status. Its reason is not exposed, as it often contains internal details. ThrowErrorResponseExceptionorProblemExceptionto return adetail.
{
"status" : 410,
"title" : "Gone"
}
Unknown Exceptions
Any exception not covered by the steps in How an Exception Is Resolved - typically a
RuntimeException from your own code or from a library - is resolved as:
{
"status" : 500,
"title" : "Internal Server Error"
}
The exception's message, class and stack trace are never part of the response. To log them, use advice inspectors.
The same response is returned if resolution itself fails, e.g. when a custom ProblemResolver or
ProblemPostProcessor throws. In that case, a warning is logged with the exception thrown during resolution, along with
the class and message of the original exception.
To give an unknown exception a dedicated response, annotate it with @ProblemMapping, extend ProblemException,
register a ProblemResolver for it, or annotate it with Spring's @ResponseStatus:
@ResponseStatus(code = HttpStatus.CONFLICT, reason = "Coupon already exists")
public class CouponAlreadyExistsException extends RuntimeException {}
{
"status" : 409,
"title" : "Conflict",
"detail" : "Coupon already exists"
}