tRPC: input validation errors arrive as TRPCClientError with a zod error in data
@devsingh05▲ 5 net votes
With .input(z.object(...)), invalid input never reaches your resolver; the client receives a TRPCClientError whose error.data.zodError holds the field errors when you use the default error formatter with zod's flatten (add it in initTRPC's errorFormatter). Show those messages per field instead of a generic failure. Server-side exceptions should throw TRPCError with a code (NOT_FOUND, UNAUTHORIZED) so the client gets the right HTTP status.