kotyan
TTCTheo's Typesafe Cult
•Created by janglad on 9/4/2023 in #questions
Prisma + Zod, where to validate uniqueness
frontend:
10 replies
TTCTheo's Typesafe Cult
•Created by janglad on 9/4/2023 in #questions
Prisma + Zod, where to validate uniqueness
10 replies
TTCTheo's Typesafe Cult
•Created by janglad on 9/4/2023 in #questions
Prisma + Zod, where to validate uniqueness
I've created a utility function validateUniqueConstraint to handle unique constraint errors from Prisma. It takes in a field name, error message, and a function that triggers a Prisma operation. If a unique constraint error occurs on the specified field, it throws a user-friendly TRPCError with the provided error message. Then I handle this error using enum on the frontend.
10 replies