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.9 Replies
stormy-gold•2mo ago
do you mean
inputValidator ?vicious-goldOP•2mo 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
stormy-gold•2mo ago
you can add a custom serialization adapter that serializes zod errors
vicious-goldOP•2mo ago
Is there any docs i can look into to add a custom serializer?
stormy-gold•2mo ago
unfortunately i didnt have the time yet
we have an example
see e2e/react-start/serialization-adapters/src/start.tsx
vicious-goldOP•2mo ago
This is exactly what i needed @Manuel Schiller ! Thanks !!
stormy-gold•2mo ago
nice
when you have the adapter ready, please share
vicious-goldOP•2mo 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.

harsh-harlequin•5w ago
@nikus I'm using a functiom middleware to catch the error,
setResponseStatus, and rethrow the error.