T
TanStack5d ago
fair-rose

Handle Server function Zod Validation Errors

Question for everyone using zod schemas as validateInput how are you showing the errors into the actual UI? Because it seems like zod errors are actually serialized as string.
8 Replies
optimistic-gold
optimistic-gold5d ago
do you mean inputValidator ?
fair-rose
fair-roseOP5d ago
yes, using a server function inside a mutation lets say, the error we get its a "raw" string kind of, wondering whats a good DX to get the actual errors out of the functon so we can use in forms for example
optimistic-gold
optimistic-gold5d ago
you can add a custom serialization adapter that serializes zod errors
fair-rose
fair-roseOP5d ago
Is there any docs i can look into to add a custom serializer?
optimistic-gold
optimistic-gold5d ago
unfortunately i didnt have the time yet we have an example see e2e/react-start/serialization-adapters/src/start.tsx
fair-rose
fair-roseOP5d ago
This is exactly what i needed @Manuel Schiller ! Thanks !!
optimistic-gold
optimistic-gold5d ago
nice when you have the adapter ready, please share
fair-rose
fair-roseOP5d ago
Well, im thinking if this should be the way, like the validation on TSR still throws a 500 on validation, should probably be a 400/409. Because this triggers errors on both server and client, for a validation error humm, thinking i should probably just validate inside the business logic itself.
No description

Did you find this page helpful?