Skip to content
Agentmart
Submit a tool

error-handling-api

Production-ready API error handling for Next.js with standardized error codes, request tracking, user-friendly messages, and automatic error wrapping.

Skill by JimmyBlanquet

IndexedMIT
Write a review

Install

Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.

npx agentmarket install skill/jimmyblanquet-error-handling-api

Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.

Get the weekly diff

The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.

We use your email only for this newsletter. Privacy

About

Production-ready API error handling for Next.js with standardized error codes, request tracking, user-friendly messages, and automatic error wrapping. Type-safe responses with logging separation.

Use cases: frontend, backend

No reviews yet. Installed it? Reviews come from verified installers only. How reviews work

Permissions

What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.

Tools
No tools found
Secrets
None asked for
Install scripts
None found
Runs as
Node.js package

Network hosts it talks to 1

  • codeload.github.com · found in install command

Files it touches

  • ~/.claude/skills/error-handling-api

What's inside

Skill name
error-handling-api
Description
Production-ready API error handling for Next.js with standardized error codes, request tracking, user-friendly messages, and automatic error wrapping. Type-safe responses with logging separation.
License
MIT
Instructions
438 lines in SKILL.md · view on GitHub

Before installing

  • Ships executable scripts

Agent Skills spec issues

  • files: referenced but missing: references/CUSTOM_ERROR_CLASSES.md, examples/01-basic-route.ts, examples/02-advanced-errors.ts, examples/03-protected-route.ts, examples/04-batch-operations.ts

Files (19)

  • README.md
  • SKILL.md
  • VALIDATION.md
  • advanced-patterns.ts · examples/
  • basic-usage.ts · examples/
  • custom-logger.ts · examples/
  • nextjs-api-route.ts · examples/
  • manifest.yaml
  • package-lock.json
  • package.json
  • error-codes.ts · src/
  • error-handler.ts · src/
  • index.ts · src/
  • types.ts · src/
  • utils.ts · src/
  • error-handler.test.ts · tests/
  • index.test.ts · tests/
  • tsconfig.json
  • vitest.config.ts

SKILL.md (first lines)

# Error Handling API

Centralized error handling system for Next.js API routes with consistent responses, request tracking, and separation between user-facing messages and technical logs.

## When to Use

Use this skill when building Next.js APIs that need:
- Consistent error response format across all endpoints
- User-friendly error messages (never expose internal details)
- Request ID tracking for debugging
- Automatic error catching and logging
- Type-safe error codes and responses
- Separation between client errors (4xx) and server errors (5xx)

**Don't use this skill if:**
- You're building a simple static site without APIs
- You need GraphQL error handling (this is REST-focused)
- You're using Next.js Pages Router (this uses App Router Route Handlers)

## Stack

- Next.js 14+ (App Router Route Handlers)
- TypeScript (strict mode)
- Optional: Logging library integration (Pino, Winston, etc.)

## Quick Start

### 1. Install Skill

```bash
npm install -D @project-forge/error-handling-api
```

### 2. Create Error Codes Dictionary

```typescript
// lib/api/errors.ts
import { API_ERROR } from '@project-forge/error-handling-api'

// Use predefined errors or extend with your own
export const AppErrors = {
  ...API_ERROR,
  CUSTOM_ERROR: {
    code: 'CUSTOM_ERROR',
    message: 'Your custom error message',
    status: 400,
  },
} as const
```

### 3. Use in API Routes

```typescript
// app/api/users/route.ts
import { apiError, apiSuccess } from '@project-forge/error-handling-api'
import { NextRequest } from 'next/server'

export async function GET(request: NextRequest) {
  const userId = request.nextUrl.searchParams.get('id')

  if (!userId) {
    return apiError('MISSING_PARAMS')
  }

  const user = await db.users.findUnique({ where: { id: userId } })

  if (!user) {
    return apiError('NOT_FOUND')
  }

  return apiSuccess(user)
}
```

### 4. Wrap Routes with Error Handler

```typescript
import { withErrorHandler } from '@project-forge/error-handling-api'

export const POST = withErrorHandler(async (request) => {
  // Any unhandled errors are caught and returned as 500
  const data = await processData()
  return apiSuccess(data)
})
```

## Key Features

### Standard Error Codes

Pre-defined error codes for common scenarios:

**Authentication (401)**
- `UNAUTHORIZED` - Authentication required
- `SESSION_EXPIRED` - Session expired, please reconnect

**Authorization (403)**
- `FORBIDDEN` - Access denied
- `RESOURCE_FORBIDDEN` - No access to this resource

**Not Found (404)**
- `NOT_FOUND` - Resource not found
- `PROFILE_NOT_FOUND`, `EMAIL_NOT_FOUND`, etc.

**Validation (400)**
- `VALIDATION_ERROR` - Invalid data
- `INVALID_PARAMS` - Invalid parameters
- `MISSING_PARAMS` - Required parameters missing

**Rate Limiting (429)**
- `RATE_LIMITED` - Too many requests

**Server Errors (500)**
- `INTERNAL_ERROR` - Internal server error
- `DATABASE_ERROR` - Database operation failed
- `SERVICE_UNAVAILABLE` - Service temporarily unavailable

### Request ID Tracking

From JimmyBlanquet/project-forge, MIT.

More from JimmyBlanquet/project-forge

Signals

Stars
0
Forks
0
Open issues
2
Last commit (this folder)
May 10, 2026 (5 months ago)

From GitHub (fetched Oct 24, 2026).

Details

License
MIT
First seen
Oct 24, 2026
Last checked
Oct 24, 2026

More from JimmyBlanquet

Cite this page

error-handling-api skill. Agent Mart. https://agentmart.dev/skills/jimmyblanquet-error-handling-api (last updated 2026-10-24)