Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.
public class ValidationException
- Object
- Throwable
- Exception
- RuntimeException
- ResponseStatusException
- 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.
Constructors
public ValidationException(List<FieldError> errors) |
Methods
Inherited methods
Constructor details
ValidationException
public ValidationException(List<FieldError> errors)Parameters
errorsList<FieldError>- what failed; at least one
Method details
getFieldErrors
public List<FieldError> getFieldErrors()Every constraint that failed, in the order the checks ran.
Returns
the errors, never empty
getFieldErrors
public List<FieldError> getFieldErrors(String field)The errors for one path.
Parameters
fieldString- the path
Returns
its errors, possibly empty
toResponse
public HttpServer.Response toResponse(HttpServer.Request request)The default answer: 400 with the errors as JSON.
Parameters
requestHttpServer.Request- the request being answered
Returns
the response