tRPCttRPC
Powered by
switzS
tRPC•9mo ago•
2 replies
switz

Preventing action from throwing error due to zod schema?

I have trpc creating server actions, fronted by a zod form data schema.

const createDatasetSchema = zfd.formData({
  name: zfd.text(
    z
      .string()
      .min(1, 'Name is required')
      .max(100, 'Name must be less than 100 characters')
      .lowercase()
      .regex(/[a-z0-9-_]/)
  ),
});
const createDatasetSchema = zfd.formData({
  name: zfd.text(
    z
      .string()
      .min(1, 'Name is required')
      .max(100, 'Name must be less than 100 characters')
      .lowercase()
      .regex(/[a-z0-9-_]/)
  ),
});


I don't want this to throw an error, I want to return errors to the frontend form (
useActionState
useActionState
) so it can render what the errors are. Is there a good way to do this?
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

Preventing uncaught error propagation from server to client
OoijazOOoijaz / ❓-help
2y ago
how to handle error from Zod in trpc?
MarMMar / ❓-help
3y ago
Zod formatting Error
Nacho EliasNNacho Elias / ❓-help
2y ago
Zod Error Middleware
zomarsZzomars / ❓-help
4y ago