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.