Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Implement standardized error handling with proper HTTP status codes and error responses. Use when implementing standardized error handling. Trigger with phrases like "add error handling", "standardize errors", or "implement error responses".
.claude/skills/jeremylongshore-handling-api-errors/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-01 | ✗→✓ | ▲ Improved | 48% | 0% |
| case-02 | ✗→✓ | ▲ Improved | 41% | 0% |
| case-03 | ✗→✓ | ▲ Improved | 85% | 0% |
| case-08 | ✗→✓ | ▲ Improved | 55% | 0% |
| case-06 | ✓→✓ | = Same ✓ | 73% | 0% |
Implement standardized API error handling with RFC 7807 Problem Details responses, centralized error middleware, typed error classes, and environment-aware stack trace exposure. Convert framework exceptions, validation failures, database errors, and upstream service failures into consistent, machine-readable error responses with appropriate HTTP status codes.
try/catch blocks, error middleware, and exception handlers, identifying inconsistent error response formats across endpoints.type (URI identifying error type), title (human-readable summary), status (HTTP code), detail (specific explanation), and instance (request path).ValidationError (400), AuthenticationError (401), AuthorizationError (403), NotFoundError (404), ConflictError (409), and RateLimitError (429).field, message, and code properties.See ${CLAUDE_SKILL_DIR}/references/implementation.md for the full implementation guide.
${CLAUDE_SKILL_DIR}/src/errors/ - Typed error classes (ValidationError, NotFoundError, etc.)${CLAUDE_SKILL_DIR}/src/middleware/error-handler.js - Centralized error handling middleware${CLAUDE_SKILL_DIR}/src/errors/formatters.js - Error-to-RFC-7807 response transformation${CLAUDE_SKILL_DIR}/src/errors/codes.js - Error code registry with human-readable descriptions${CLAUDE_SKILL_DIR}/src/config/error-config.js - Environment-aware error detail configuration${CLAUDE_SKILL_DIR}/tests/errors/ - Error handling tests for each error type and scenario| Error | Cause | Solution | |-------|-------|----------| | Stack trace leaked | Error handler omits production check; raw Error thrown without wrapping | Verify NODE_ENV/APP_ENV check in error formatter; wrap all thrown errors in typed classes | | Inconsistent error format | Some endpoints return {error: "msg"} while others return RFC 7807 | Ensure all errors flow through centralized middleware; remove per-handler try/catch that formats differently | | Unhandled promise rejection | Async handler throws without catch; Express does not catch async errors | Use express-async-errors wrapper or explicit async error forwarding with next(err) | | Database error exposed | Raw SQL error message returned to client containing table/column names | Map database errors to generic messages at the error handler layer; log full details server-side | | Error monitoring noise | High volume of expected 4xx errors flooding Sentry/Bugsnag | Configure error monitoring to capture only 5xx; track 4xx via metrics, not error monitoring |
Refer to ${CLAUDE_SKILL_DIR}/references/errors.md for comprehensive error patterns.
RFC 7807 response: {"type":"https://api.example.com/errors/validation","title":"Validation Error","status":400,"detail":"Request body contains 2 validation errors","errors":[{"field":"email","message":"Invalid email format","code":"INVALID_FORMAT"}]}
Centralized Express error handler: Single app.use((err, req, res, next) => {...}) middleware that handles all error types, sets status codes, formats RFC 7807 bodies, logs with correlation ID, and reports to Sentry.
Graceful upstream failure: When a downstream payment service returns 500, wrap it in a ServiceUnavailableError with a user-friendly message, log the upstream response for debugging, and trigger a circuit breaker.
See ${CLAUDE_SKILL_DIR}/references/examples.md for additional examples.
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-06 | pass→pass | 24,657 | 38,783 | +57% | 1 | 1 | 0% | 3,866 | 6,678 | +73% | 0 | 0 | — |
case-07 | fail→fail | 16,313 | 15,043 | -8% | 1 | 1 | 0% | 2,804 | 4,049 | +44% | 0 | 0 | — |
case-12 | pass→pass | 21,999 | 25,292 | +15% | 1 | 1 | 0% | 3,633 | 5,072 | +40% | 0 | 0 | — |
case-13 | pass→pass | 22,098 | 20,280 | -8% | 1 | 1 | 0% | 2,875 | 3,969 | +38% | 0 | 0 | — |
case-14 | pass→pass | 21,536 | 50,847 | +136% | 1 | 1 | 0% | 2,823 | 5,698 | +102% | 0 | 0 | — |
case-05 | pass→pass | 16,315 | 23,666 | +45% | 1 | 1 | 0% | 3,367 | 6,320 | +88% | 0 | 0 | — |
case-01 | fail→pass | 35,037 | 42,351 | +21% | 1 | 1 | 0% | 6,452 | 9,529 | +48% | 0 | 0 | — |
case-02 | fail→pass | 31,927 | 49,622 | +55% | 1 | 1 | 0% | 6,220 | 8,760 | +41% | 0 | 0 | — |
case-03 | fail→pass | 34,453 | 41,536 | +21% | 1 | 1 | 0% | 5,001 | 9,275 | +85% | 0 | 0 | — |
case-04 | pass→pass | 24,449 | 31,116 | +27% | 1 | 1 | 0% | 3,739 | 6,599 | +76% | 0 | 0 | — |
case-08 | fail→pass | 17,551 | 16,620 | -5% | 1 | 1 | 0% | 2,206 | 3,430 | +55% | 0 | 0 | — |
case-09 | pass→pass | 16,716 | 15,721 | -6% | 1 | 1 | 0% | 2,318 | 3,416 | +47% | 0 | 0 | — |
case-10 | pass→pass | 19,563 | 9,594 | -51% | 1 | 1 | 0% | 2,110 | 2,091 | -1% | 0 | 0 | — |
case-11 | pass→pass | 16,824 | 15,165 | -10% | 1 | 1 | 0% | 2,259 | 3,274 | +45% | 0 | 0 | — |
case-15 | fail→fail | 22,044 | 14,295 | -35% | 1 | 1 | 0% | 2,845 | 3,815 | +34% | 0 | 0 | — |
case-16 | pass→pass | 17,683 | 26,026 | +47% | 1 | 1 | 0% | 3,082 | 4,356 | +41% | 0 | 0 | — |
case-17 | pass→pass | 17,956 | 13,994 | -22% | 1 | 1 | 0% | 2,301 | 3,362 | +46% | 0 | 0 | — |
case-18 | pass→pass | 15,852 | 7,773 | -51% | 1 | 1 | 0% | 1,841 | 2,725 | +48% | 0 | 0 | — |
case-19 | pass→pass | 22,331 | 17,683 | -21% | 1 | 1 | 0% | 3,090 | 3,463 | +12% | 0 | 0 | — |
case-20 | pass→pass | 19,688 | 24,362 | +24% | 1 | 1 | 0% | 3,561 | 4,227 | +19% | 0 | 0 | — |
case-21 | pass→pass | 7,330 | 9,511 | +30% | 1 | 1 | 0% | 1,434 | 2,057 | +43% | 0 | 0 | — |
case-22 | pass→pass | 5,761 | 10,435 | +81% | 1 | 1 | 0% | 1,013 | 2,222 | +119% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted. The headline lift of +18 percentage points is the difference between those two pass rates over the 22 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.