Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.

public class ValidationException

  1. Object
  2. Throwable
  3. Exception
  4. RuntimeException
  5. ResponseStatusException
  6. 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

public List<FieldError> getFieldErrors()Every constraint that failed, in the order the checks ran.
public List<FieldError> getFieldErrors(String field)The errors for one path.
public HttpServer.Response toResponse(HttpServer.Request request)The default answer: 400 with the errors as JSON.

Inherited methods

Constructor details

ValidationException

public ValidationException(List<FieldError> errors)

Parameters

errors List<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

field String
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

request HttpServer.Request
the request being answered

Returns

the response