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
- Handling tRPC Errors Gracefully
- Custom Error Types
- Data Transformers for Serialization
- Formatting Errors and Field-Level Validation Feedback