Handling Validation Errors in Actions
Return validation errors and repopulate form fields using fail() and ActionData.
The fail Helper
Use fail() to return validation errors with a non-2xx status without throwing.
import { fail } from "@sveltejs/kit";
if (!email) return fail(400, { email, missing: true });Status Code
First argument is the HTTP status (usually 400 for validation).
All lessons in this course
- +page.server.js with actions
- The use:enhance Directive
- Progressive Enhancement for Forms
- Handling Validation Errors in Actions