error-handling

Standardize API error handling with structured AppError classes and middleware.

Updated Jan 30, 2026
One-click install
npx skills add https://github.com/jrmatherly/metorial-workspace --skill error-handling-jrmatherly
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: error-handling
Source: https://github.com/jrmatherly/metorial-workspace/tree/main/.github/skills/error-handling
Command: npx skills add https://github.com/jrmatherly/metorial-workspace --skill error-handling-jrmatherly

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Standardize and centralize error handling across API servers and services to ensure consistent, actionable, and user-friendly error responses.

Core Features & Use Cases

  • Custom error classes and a unified error response contract for API endpoints.
  • Middleware/handler implementations for Express, FastAPI, and frontend clients to translate internal errors into structured, safe outputs.
  • Example patterns for NotFound, Validation, Unauthorized, Forbidden, Conflict, and RateLimit errors across languages.

Quick Start

Create a base AppError class and several specific errors in your backend. Wire a global error handler/middleware in your framework and wrap async routes with an async handler. Use the provided patterns to produce consistent, secure error responses and include trace information for debugging.

Frequently Asked Questions about error-handling

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

FAQPage Schema
How do I standardize error handling across REST APIs and microservices?

Standardize REST API error handling by implementing a base AppError class with structured fields, a framework-agnostic global handler, and async route wrappers. This ensures consistent, safe, and traceable error outputs across microservices.

How do I return consistent error responses for validation and authentication failures in TypeScript?

Consistent TypeScript error responses for validation and authentication failures are achieved using custom error classes and a unified response contract. Middleware translates internal exceptions into structured, secure outputs with trace information.

Can I use this error-handling approach with both Express and FastAPI?

Yes, the error-handling approach works with both Express and FastAPI. It provides middleware and handler implementations for both frameworks to translate internal errors into a unified, structured output contract.

What is the best way to sanitize internal API errors before sending them to frontend clients?

The best way to sanitize API errors is using a framework-agnostic global error handler. It intercepts internal exceptions, including external service failures, and translates them into safe, structured outputs without exposing sensitive stack traces.

How do I wrap async routes to catch unhandled exceptions in Python APIs?

Wrap async Python API routes using provided async route wrappers. These catch unhandled exceptions and pass them to a global error handler, ensuring all failures produce structured, traceable outputs.

Why do I need a custom AppError class instead of throwing standard exceptions in microservices?

A custom AppError class is needed to attach structured fields and trace information to exceptions. This allows a centralized handler to produce actionable, user-friendly API responses instead of inconsistent default error formats.