validateOrReject method

void validateOrReject()

Throws a 422 Rejection when this value fails its constraints.

The counterpart to validateOrThrow, which throws a ValidationException that means nothing to HTTP. Use it inside a guard when the value did not come through ValidatedExtractable:

return guard(() async {
  final input = await const JsonExtractable(CreateTodo.deserialize)
      .require(request);
  input.validateOrReject();
  ...
});

Implementation

void validateOrReject() {
  final rejection = validate().rejection;
  if (rejection != null) throw rejection;
}