0Pricing
tRPC End-to-End Type Safe APIs · Lesson

Formatting Errors and Field-Level Validation Feedback

Customize how tRPC errors are shaped and surface clean field-level validation messages to your client.

Why Format Errors?

You can throw and catch tRPC errors. But clients often need structured error data, especially field-level messages from validation, to show next to form inputs.

The errorFormatter Option

tRPC lets you customize the error shape globally with errorFormatter when initializing.

const t = initTRPC.create({
  errorFormatter({ shape }) {
    return shape;
  },
});

All lessons in this course

  1. Handling tRPC Errors Gracefully
  2. Custom Error Types
  3. Data Transformers for Serialization
  4. Formatting Errors and Field-Level Validation Feedback
← Back to tRPC End-to-End Type Safe APIs