error-handling

Create structured API error responses with specialized error classes and middleware.

7|Updated Dec 4, 2025
One-click install
npx skills add https://github.com/planetaryescape/blah.chat --skill error-handling-planetaryescape
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: error-handling
Source: https://github.com/planetaryescape/blah.chat/tree/main/.claude/skills/error-handling
Command: npx skills add https://github.com/planetaryescape/blah.chat --skill error-handling-planetaryescape

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Provides a structured ApiError hierarchy and safe error handling to standardize API responses and improve reliability.

Core Features & Use Cases

  • ApiError base class with statusCode, code, and message
  • Specialized errors: BadRequestError, UnauthorizedError, ForbiddenError, NotFoundError, ConflictError, InternalServerError
  • withErrorHandling middleware to centralize error handling
  • Zod validation error handling integration
  • Formatted error envelope responses via formatErrorEntity
  • Structured logging with consistent fields

Quick Start

Install or import the error handling modules in your project, wrap API routes with withErrorHandling, and throw the specialized errors in routes to trigger standardized 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 API error responses in a Next.js application?

Standardize API error responses in Next.js by wrapping routes with the withErrorHandling middleware and throwing specialized ApiError subclasses to trigger a uniform formatted error envelope. This centralizes handling and ensures consistent response formats.

What is the best way to handle Zod validation errors in API routes?

Handle Zod validation errors by integrating them into the withErrorHandling middleware, which maps schema failures to BadRequestError instances. This converts validation issues into a standardized API error envelope with consistent fields.

Does this API error handling system work with Convex backend actions?

Yes, this error handling system works with Convex. The ApiError hierarchy and middleware are designed for modern web apps including Next.js, Convex, and Zod, applying structured error responses to validation, authentication, and not-found scenarios.

What types of HTTP errors can I standardize for my web API?

You can standardize web API errors using specialized classes including BadRequestError, UnauthorizedError, ForbiddenError, NotFoundError, ConflictError, and InternalServerError. Each extends the base ApiError class with specific status codes.

How do I return a consistent error envelope from my API routes?

Return a consistent error envelope from API routes by using the formatErrorEntity function. It structures the ApiError instance into a standardized response format, ensuring clients receive uniform error codes and messages across all endpoints.

Why should I use a centralized error handling middleware instead of try-catch blocks?

Centralized error handling middleware standardizes API responses and improves reliability better than scattered try-catch blocks. It captures thrown ApiError instances uniformly, applies structured logging, and formats a consistent error envelope.