error-handling

Standardize tRPC backend error handling with TRPCError and HTTP status mappings.

2|Updated Apr 11, 2026
One-click install
npx skills add https://github.com/PlazaCC/antes-da-tela --skill error-handling-plazacc
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: error-handling
Source: https://github.com/PlazaCC/antes-da-tela/tree/main/.agents/skills/error-handling
Command: npx skills add https://github.com/PlazaCC/antes-da-tela --skill error-handling-plazacc

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Standardize error handling in tRPC backends using TRPCError and consistent HTTP status mappings.

Core Features & Use Cases

  • Throw typed TRPCError with codes like NOT_FOUND, UNAUTHORIZED, BAD_REQUEST, and INTERNAL_SERVER_ERROR to produce predictable client responses.
  • Wrap original errors with a cause to preserve stack traces and enable rich debugging.
  • Customize client-facing error payloads with an errorFormatter and route global errors via onError for centralized logging.

Quick Start

Configure a tRPC router with a custom errorFormatter and throw TRPCError for known error codes to ensure consistent client responses.

Frequently Asked Questions about error-handling

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I standardize tRPC error handling with TRPCError and HTTP status mappings?

Standardize tRPC error handling by throwing typed TRPCError instances with specific codes like NOT_FOUND or UNAUTHORIZED, and configuring a custom errorFormatter to map these codes to predictable HTTP status responses for clients.

What is the best way to customize client-facing error payloads in a tRPC backend?

Customize client-facing error payloads in a tRPC backend by implementing a custom errorFormatter, which transforms the default TRPCError output into a structured, predictable format for client applications.

How do I preserve stack traces when wrapping errors in tRPC?

Preserve stack traces in tRPC by wrapping original errors with a cause property when throwing a TRPCError, ensuring rich debugging information remains intact throughout the server-side procedure execution.

Does this error handling approach require @trpc/server to function?

Yes, this error handling approach requires the @trpc/server dependency to function, as it relies on the native TRPCError class and the tRPC router's errorFormatter configuration to map HTTP statuses correctly.

Why are my tRPC server errors returning inconsistent HTTP status codes?

tRPC server errors return inconsistent HTTP status codes when procedures lack a custom errorFormatter, making it necessary to standardize TRPCError codes like BAD_REQUEST and INTERNAL_SERVER_ERROR for predictable client responses.

How do I route global tRPC errors for centralized logging?

Route global tRPC errors for centralized logging by configuring the onError property within the tRPC router, capturing unhandled TRPCError instances before they reach the custom errorFormatter.