add-error-code

Adds contract error codes as enum members and named NestJS exception classes.

Updated Jul 26, 2026
One-click install
npx skills add https://github.com/aymansalkhatib/medledger --skill add-error-code-aymansalkhatib
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: add-error-code
Source: https://github.com/aymansalkhatib/medledger/tree/main/.claude/skills/add-error-code
Command: npx skills add https://github.com/aymansalkhatib/medledger --skill add-error-code-aymansalkhatib

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Adding a new API error in this NestJS codebase requires coordinated edits across the ErrorCode enum, a dedicated exception class, and the throwing call site — and mistakes break the API contract that the verification harness asserts exactly. This Skill walks through that workflow so every error renders as the contract-mandated { error: { code, message }, serverTime } envelope. ## Core Features & Use Cases - Contract validation: Checks the code against API_CONTRACT.md before adding it, since the harness asserts the contract's spelling exactly. - Enum and exception generation: Appends the UPPER_SNAKE member to error-code.enum.ts and creates a one-level-deep exception class whose Nest base class carries the HTTP status (401/404/409/422). - Call-site migration: Replaces bare Nest exception throws with the named exception that takes facts, not prose messages. - Use Case: A service throws new ConflictException('not enough stock') and the harness expects INSUFFICIENT_STOCK — run this Skill to add the enum member, create InsufficientStockException, and rewire the throw. ## Quick Start Ask the assistant to add the error code INSUFFICIENT_STOCK as a 409 in the holdings module and replace the bare ConflictException throw.

Frequently Asked Questions about add-error-code

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

FAQPage Schema
How do I add a custom error code in a NestJS API?▼

Add an UPPER_SNAKE member to the ErrorCode enum, then create a dedicated exception class extending the Nest base exception with the right HTTP status. Replace bare throws at the call site with the new class so the global filter renders the contract envelope.

How do I return a specific HTTP status like 409 from a NestJS exception?▼

Extend the Nest base exception that carries the status: UnauthorizedException for 401, NotFoundException for 404, ConflictException for 409, or UnprocessableEntityException for 422. The status comes from the base class, not from a manual argument.

Why does my NestJS error response miss the error code field?▼

The global exception filter only renders the code when the thrown exception body contains a code property. Throwing a bare Nest exception with a plain message string is treated as a framework error and the contract code is lost.

Can I create a generic AppException that takes the error code as an argument?▼

No. The convention is one exception class per code, with the constructor taking facts like IDs and limits rather than a message. A generic class taking code and message arguments is an explicit anti-pattern in this codebase.

Should I subclass an existing custom exception to reuse its behavior?▼

No. The exception hierarchy stays one level deep because nothing dispatches on the class, only on the code value. Always extend a Nest base exception directly and never subclass one of the project's own exception classes.