Ferra.rs / Error Types / validation_failed

validation_failed

Validation Failed

422 Unprocessable Content

Returned when the request body is structurally valid JSON that deserialises into the model's request shape, but one or more #[field(…)] rule constraints fail — for example min_length, max, or pattern. Every failing field is reported in a single response; the framework never short-circuits on the first violation.

This is distinct from validation (400), which fires when the body cannot be parsed or a path parameter fails deserialisation. A 400 means "fix your request shape"; a 422 means "fix your field values."

Example RFC 7807 body — multiple fields

{
  "type":   "https://ferra.rs/errors/validation_failed",
  "title":  "Validation Failed",
  "status": 422,
  "detail": "validation failed",
  "errors": {
    "title":  ["must be at least 1 character"],
    "rating": ["must be at most 10"]
  }
}

errors map

Keys are wire-side field names (the JSON key the client submitted, respecting any serde rename attributes). Values are non-empty arrays of human-readable English messages, one per failed rule. The shape is Map<String, Vec<String>> and is stable across POST (create) and PUT (update) endpoints.

how to handle

Iterate errors, surface each message next to the relevant form field, and let the user correct the values. No re-serialisation of the request envelope is needed — the structure was accepted; only the values were rejected.

← All error types