AES Encryption Explained: How It Works and Why It Matters
Jun 23, 2026
4xx Client Error
The 422 (Unprocessable Content) status code indicates that the server understands the content type and syntax of the request body but was unable to process the contained instructions. In REST APIs, this is commonly used for validation errors — the request format is correct but the data is invalid.
When a user submits a registration form with an invalid email and a password that is too short, return 422 Unprocessable Content with a structured error response listing each failed field and the corresponding validation message. This enables frontend clients to display inline errors next to each form field.
// Laravel - validation errors return 422 automatically
$request->validate([
'email' => 'required|email',
'password' => 'required|min:8',
]);
// Returns {"message": "...", "errors": {"email": [...], "password": [...]}} with 422
Mistake: Returning 400 for validation errors instead of 422
Fix: Use 422 Unprocessable Content for validation errors where the request body is syntactically valid but the data is invalid. Reserve 400 for malformed syntax like invalid JSON.
Mistake: Returning 422 with a flat error message instead of per-field errors
Fix: Structure validation error responses as an object with field names as keys and arrays of error messages as values. This enables frontend frameworks to display errors next to specific form fields.
Mistake: Including stack traces or debug info in 422 responses in production
Fix: Validation error responses should contain user-friendly messages, not internal debug information. Keep stack traces and internal details out of production API responses.
Blog
Jun 23, 2026
Jun 23, 2026
Jun 23, 2026
Jun 23, 2026
Jun 23, 2026
Jun 23, 2026