error-handling

Classify Node.js/Express/MongoDB errors into safe HTTP responses.

Updated Aug 23, 2026
One-click install
npx skills add https://github.com/paulinett1508-dev/SuperCartolaManagerv5-production --skill error-handling-paulinett1508-dev
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: error-handling
Source: https://github.com/paulinett1508-dev/SuperCartolaManagerv5-production/tree/main/.claude/skills/error-handling
Command: npx skills add https://github.com/paulinett1508-dev/SuperCartolaManagerv5-production --skill error-handling-paulinett1508-dev

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill prevents unstable or insecure API behavior by standardizing how operational vs programming errors are classified, logged, and translated into safe HTTP responses across the Super Cartola Manager backend.

Core Features & Use Cases

  • Error classification hierarchy: Distinguishes operational errors (like 400/401/403/404/409/429) from programming/bug errors (mapped to 500) to avoid confusing clients and masking real issues.
  • Middleware-friendly response strategy: Recommends using the existing utils/apiResponse.js helpers (apiSuccess, apiError, apiServerError, apiUnauthorized, apiConflict) and centralized error handling patterns for Express.
  • Secure, structured logging: Uses utils/logger.js with safe context (e.g., ligaId, timeId, operation) while explicitly avoiding sensitive data (tokens, passwords, MONGO_URI, cookies).
  • MongoDB error mapping: Converts common MongoDB/Mongoose failure modes (e.g., E11000 duplicate keys, CastError, ValidationError, timeouts) into consistent client responses.
  • Client response safety rules: Ensures stack traces and internal server details are not exposed in production, and avoids leaking DB internals.

Quick Start

Apply consistent try/catch patterns in async controllers and return operational failures with apiError/apiConflict/apiUnauthorized, while sending unexpected failures via apiServerError and logging full details safely with utils/logger.js.

Frequently Asked Questions about error-handling

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

FAQPage Schema
How do I handle errors consistently in a Node.js Express MongoDB backend?

To handle errors consistently in a Node.js Express MongoDB backend, classify failures as operational or programming errors, map MongoDB exceptions to HTTP responses, and route them through centralized Express middleware.

What is the best way to map MongoDB Mongoose errors to HTTP responses in Express?

Mapping MongoDB Mongoose errors to HTTP responses involves converting failure modes like E11000 duplicate keys, CastError, and ValidationError into consistent client-facing API responses without leaking database internals.

How do I prevent sensitive data from leaking in Node.js structured error logs?

Preventing sensitive data leaks in Node.js structured error logs requires using secure logging utilities that capture safe context like operation IDs while explicitly avoiding tokens, passwords, and connection strings.

Does this error handling approach support multi-tenant security in Express APIs?

Yes, this error handling approach supports multi-tenant security in Express APIs by ensuring error classification and logging maintain strict data isolation boundaries for operations like league management.

How do I distinguish operational errors from programming errors in an Express API?

Distinguishing operational errors from programming errors in an Express API involves mapping expected failures like validation or authorization issues to specific HTTP status codes, while routing unexpected bugs to 500 responses.

Why should I use centralized Express middleware for API error handling?

Using centralized Express middleware for API error handling ensures stack traces and internal server details are never exposed in production, providing safe and standardized client error output across the application.