Preventing raw Zod error exposure in createServerFn validation
Hi everyone! 👋
I'm using createServerFn with .inputValidator() using a Zod schema. When the input validation fails, the server function throws the raw Zod error array to the client.
I would like to know if there is a recommended way to intercept this validation error to return a simplified message (e.g., just "Invalid UUID") or a custom error structure, instead of exposing the full Zod error object.
Example:
When I call this function with an invalid UUID, I receive this raw Zod error response:
I want to be able to return something cleaner, like: { "message": "Invalid UUID" } or just throw a standard HTTP error(Bad Request).
Is there a hook or middleware configuration to handle
inputValidator failures?
0 Replies