Class ValidationException
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
com.codename1.backend.ResponseStatusException
com.codename1.backend.validation.ValidationException
A request whose input broke its declared constraints.
Thrown by the generated router before the controller method runs, so nothing
the method does happens for invalid input. An @ExceptionHandler for it may
shape the answer; unhandled, the request is answered 400 with
{"status":400,"error":"Bad Request",
"errors":[{"field":"address.zip","code":"Size","message":"size must be between 5 and 5"}]}
An application may throw it too, for a check no annotation expresses.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionEvery constraint that failed, in the order the checks ran.getFieldErrors(String field) The errors for one path.toResponse(HttpServer.Request request) The default answer: 400 with the errors as JSON.Methods inherited from class ResponseStatusException
getReason, getStatusMethods inherited from class Throwable
addSuppressed, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Constructor Details
-
ValidationException
- Parameters:
errors- what failed; at least one
-
-
Method Details
-
getFieldErrors
Every constraint that failed, in the order the checks ran.- Returns:
- the errors, never empty
-
getFieldErrors
The errors for one path.- Parameters:
field- the path- Returns:
- its errors, possibly empty
-
toResponse
The default answer: 400 with the errors as JSON.- Parameters:
request- the request being answered- Returns:
- the response
-