error-handling

Standardize Node/Express error handling with AppError classes and middleware.

3|Updated May 28, 2026
One-click install
npx skills add https://github.com/mahg-es/araya --skill error-handling-mahg-es
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: error-handling
Source: https://github.com/mahg-es/araya/tree/main/skills/error-handling
Command: npx skills add https://github.com/mahg-es/araya --skill error-handling-mahg-es

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Inconsistent error handling leads to information leakage (stack traces to users), lost debugging context (no logs), and confusing API responses. This skill establishes a single error-handling pattern used by every endpoint and service.

Core Features & Use Cases

  • Error classes: A hierarchy of AppError types (NotFoundError, ValidationError, UnauthorizedError, ForbiddenError, ConflictError) with portable codes and details.
  • Error handler middleware: Catches AppError and returns structured JSON with proper HTTP status; unknown errors are logged and return a generic 500.
  • Guardrails & health checks: Enforces logging rules, request context, and includes a health-check endpoint to exercise error handling.

Quick Start

Implement the AppError hierarchy and error-handler middleware in your project, then expose a health-check endpoint to exercise the pattern.

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 in Node and Express APIs?▼

To standardize error handling in Express APIs, implement a hierarchy of AppError types with status codes and use error-handler middleware to catch AppError instances and return structured JSON responses. This prevents information leakage and ensures consistent API responses.

Why does inconsistent API error handling cause security issues?▼

Inconsistent API error handling causes security issues by leaking sensitive information like stack traces to users and losing debugging context. A unified error-handling pattern with proper logging rules and generic 500 responses for unknown errors prevents this exposure.

How do I return consistent HTTP status codes for API errors?▼

You can return consistent HTTP status codes by defining a hierarchy of AppError types, such as NotFoundError or ValidationError, each mapped to specific status codes. The error-handler middleware catches these AppError instances and returns the appropriate HTTP status in structured JSON.

What is the best way to log Express API errors for debugging?▼

The best way to log Express API errors for debugging is to enforce logging rules within dedicated error-handler middleware. This middleware catches AppError types, logs unknown errors with request context, and returns generic 500 responses to clients without leaking stack traces.

Can I use custom error classes with Express middleware?▼

Yes, you can use custom error classes with Express middleware by creating a hierarchy of AppError types like NotFoundError and UnauthorizedError. The error-handler middleware catches these custom AppError instances to return structured JSON with proper HTTP status codes and portable error details.

Does this error-handling pattern include a health-check endpoint?▼

Yes, this error-handling pattern includes a health-check endpoint to exercise the error-handling implementation. This endpoint verifies that your AppError hierarchy, error-handler middleware, and logging rules are functioning correctly across your Node and Express services.