Class HandlerMethodValidationException
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
org.springframework.web.method.annotation.HandlerMethodValidationException
- All Implemented Interfaces:
Serializable
,MethodValidationResult
,ErrorResponse
public class HandlerMethodValidationException
extends ResponseStatusException
implements MethodValidationResult
ResponseStatusException
that is also MethodValidationResult
.
Raised by HandlerMethodValidator
in case of method validation errors
on a web controller method.
The ErrorResponseException.getStatusCode()
is 400 for input validation errors, and 500
for validation errors on a return value.
- Since:
- 6.1
- Author:
- Rossen Stoyanchev
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Contract to handle validation results with callbacks by controller method parameter type, withHandlerMethodValidationException.Visitor.other(org.springframework.validation.method.ParameterValidationResult)
serving as the fallthrough.Nested classes/interfaces inherited from interface org.springframework.web.ErrorResponse
ErrorResponse.Builder, ErrorResponse.Interceptor
-
Constructor Summary
ConstructorDescriptionHandlerMethodValidationException
(MethodValidationResult validationResult) HandlerMethodValidationException
(MethodValidationResult validationResult, Predicate<MethodParameter> modelAttributePredicate, Predicate<MethodParameter> requestParamPredicate) -
Method Summary
Modifier and TypeMethodDescriptionReturn errors from cross-parameter validation.Object[]
Return arguments to use along with amessage code
to resolve the problem "detail" for this exception through aMessageSource
.Object[]
getDetailMessageArguments
(MessageSource messageSource, Locale locale) Variant ofErrorResponse.getDetailMessageArguments()
that uses the givenMessageSource
for resolving the message argument values.Return the method to which validation was applied.Return all validation results per method parameter, including bothMethodValidationResult.getValueResults()
andMethodValidationResult.getBeanResults()
.Return the target of the method invocation to which validation was applied.boolean
Whether the violations are for a return value.void
Provide aVisitor
to handleParameterValidationResult
s through callback methods organized by controller method parameter type.Methods inherited from class org.springframework.web.server.ResponseStatusException
getHeaders, getMessage, getReason, getResponseHeaders, updateAndGetBody
Methods inherited from class org.springframework.web.ErrorResponseException
getBody, getDetailMessageCode, getStatusCode, setDetail, setInstance, setTitle, setType
Methods inherited from class org.springframework.core.NestedRuntimeException
contains, getMostSpecificCause, getRootCause
Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.springframework.web.ErrorResponse
getTitleMessageCode, getTypeMessageCode
Methods inherited from interface org.springframework.validation.method.MethodValidationResult
getAllErrors, getAllValidationResults, getBeanResults, getValueResults, hasErrors
-
Constructor Details
-
HandlerMethodValidationException
-
HandlerMethodValidationException
public HandlerMethodValidationException(MethodValidationResult validationResult, Predicate<MethodParameter> modelAttributePredicate, Predicate<MethodParameter> requestParamPredicate)
-
-
Method Details
-
getDetailMessageArguments
Description copied from interface:ErrorResponse
Variant ofErrorResponse.getDetailMessageArguments()
that uses the givenMessageSource
for resolving the message argument values.This is useful for example to expand message codes from validation errors.
The default implementation delegates to
ErrorResponse.getDetailMessageArguments()
, ignoring the suppliedMessageSource
andLocale
.- Specified by:
getDetailMessageArguments
in interfaceErrorResponse
- Parameters:
messageSource
- theMessageSource
to use for the lookuplocale
- theLocale
to use for the lookup
-
getDetailMessageArguments
Description copied from interface:ErrorResponse
Return arguments to use along with amessage code
to resolve the problem "detail" for this exception through aMessageSource
. The arguments are expanded into placeholders of the message value, e.g. "Invalid content type {0}".- Specified by:
getDetailMessageArguments
in interfaceErrorResponse
- Overrides:
getDetailMessageArguments
in classErrorResponseException
-
getTarget
Description copied from interface:MethodValidationResult
Return the target of the method invocation to which validation was applied.- Specified by:
getTarget
in interfaceMethodValidationResult
-
getMethod
Description copied from interface:MethodValidationResult
Return the method to which validation was applied.- Specified by:
getMethod
in interfaceMethodValidationResult
-
isForReturnValue
public boolean isForReturnValue()Description copied from interface:MethodValidationResult
Whether the violations are for a return value. If true the violations are from validating a return value. If false the violations are from validating method arguments.- Specified by:
isForReturnValue
in interfaceMethodValidationResult
-
getParameterValidationResults
Description copied from interface:MethodValidationResult
Return all validation results per method parameter, including bothMethodValidationResult.getValueResults()
andMethodValidationResult.getBeanResults()
.Use
MethodValidationResult.getCrossParameterValidationResults()
for access to errors from cross-parameter validation.- Specified by:
getParameterValidationResults
in interfaceMethodValidationResult
- See Also:
-
getCrossParameterValidationResults
Description copied from interface:MethodValidationResult
Return errors from cross-parameter validation.- Specified by:
getCrossParameterValidationResults
in interfaceMethodValidationResult
-
visitResults
Provide aVisitor
to handleParameterValidationResult
s through callback methods organized by controller method parameter type.
-