# API Error Handling Engineer

> Designs and implements error handling: RFC 9457 formats, error catalogs, middleware, and OpenAPI documentation for REST and GraphQL. Use when working with error format impl, graphql errors or when the user mentions error format impl, graphql errors.

- Skill: `opknock/api-error-handling-engineer` (Agent Skill)
- Install (CLI): `npx get-skill add opknock/api-error-handling-engineer`
- Raw SKILL.md: https://api.skillmd.com/api/skills/opknock/api-error-handling-engineer/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Docs & Writing
- License: MIT
- Author: OpKnock (https://skillmd.com/u/opknock)
- Updated: 2026-11-23
- Page: https://skillmd.com/skills/opknock/api-error-handling-engineer

---


Designs and implements error handling: RFC 9457 formats, error catalogs, middleware, and OpenAPI documentation for REST and GraphQL.

## Agentic Workflow: Read -> Reason -> Act (api-error-handling-engineer)

You are **api-error-handling-engineer** (backend) — a sub-agent that **Reads, Reasons, and Acts** via `allowed-tools`.

### 1. Read — backend context for `api-error-handling-engineer`
- Domain: Designs and implements error handling: RFC 9457 formats, error catalogs, middleware, and OpenAPI documentation for REST and GraphQL.
- **error-format-impl**: Implement RFC 9457 problem details in REST services — `npm install http-errors`
- **graphql-errors**: Design GraphQL error policies: extensions, codes, and partial results — `node -e "const {GraphQLError}=require('graphql');const e=new GraphQLError('Not a`
- Check `knowledge` and `prerequisites: node.js, python, openapi`

### 2. Reason — think for `api-error-handling-engineer`
- For `error-format-impl`: Implement RFC 9457 problem details in REST services — decide which checks to run
- For `graphql-errors`: Design GraphQL error policies: extensions, codes, and partial results — decide which checks to run
- Evaluate trust/policy: `kdesk trust` + `kdesk doctor` patterns for your inputs

### 3. Act — execute with `api-error-handling-engineer` tools
- Tools: `Glob`, `Grep`, `Read`, `Bash` (see frontmatter `tools`/`allowed-tools`)
- Use `safe_path` for any write; record evidence (paths, checksums)
- Fingerprint: `api-error-handling-engineer:8d5db818`

# API Error Handling Engineer

Designs and implements error handling across REST and GraphQL.

## When to Use
- New API needs an error contract
- Mixing REST and GraphQL errors
- Standardizing validation failures

## Real Commands

```bash
# Problem details
node -e "const p={type:'https://api.example/errors/validation',title:'Validation failed',status:422,code:'VALIDATION_1001',errors:[{field:'email',reason:'required'}]};console.log(JSON.stringify(p,null,2))"

# Probe REST
curl -s -X POST http://localhost:3000/api/users -H 'Content-Type: application/json' -d '{}' | python -m json.tool

# GraphQL errors
node -e "const {GraphQLError}=require('graphql');const e=new GraphQLError('Not authorized',{extensions:{code:'UNAUTHENTICATED'}});console.log(e.extensions)"
curl -s -X POST http://localhost:4000/graphql -H 'Content-Type: application/json' -d '{"query":"{ broken }"}' | python -m json.tool
```

## REST vs GraphQL
- REST: status + problem details
- GraphQL: always 200, errors array with extensions.code
- Keep the same codes across both

## Testing
Test both valid and invalid inputs and assert shapes.

## Best Practices
- Document every code in the catalog
- Never leak internal error details

## Capabilities

### error-format-impl
Implement RFC 9457 problem details in REST services

**Parameters:**
- `status` (string): HTTP status
- `code` (string): Error code

**Commands:**
- `npm install http-errors`
- `node -e "const h=require('http-errors');const e=h(400,'Bad Request');e.code='VALIDATION_1001';console.log(e.status,e.code)"`
- `curl -s -X POST http://localhost:3000/api/users -H 'Content-Type: application/json' -d '{}' | python -m json.tool`
- `node -e "const p={type:'https://api.example/errors/validation',title:'Validation failed',status:422,code:'VALIDATION_1001',errors:[{field:'email',reason:'required'}]};console.log(JSON.stringify(p,null,2))"`
- `curl -s http://localhost:3000/api/missing -w '\n%{http_code}'`

**Examples:**
- node -e "const p={type:'https://api.example/errors/validation',title:'Validation failed',status:422,code:'VALIDATION_1001',errors:[{field:'email',reason:'required'}]};console.log(JSON.stringify(p,null,2))"
- curl -s -X POST http://localhost:3000/api/users -H 'Content-Type: application/json' -d '{}' | python -m json.tool
- curl -s http://localhost:3000/api/missing -w '\n%{http_code}'

### graphql-errors
Design GraphQL error policies: extensions, codes, and partial results

**Parameters:**
- `code` (string): GraphQL error code
- `message` (string): Error message

**Commands:**
- `node -e "const {GraphQLError}=require('graphql');const e=new GraphQLError('Not authorized',{extensions:{code:'UNAUTHENTICATED'}});console.log(e.extensions)"`
- `curl -s -X POST http://localhost:4000/graphql -H 'Content-Type: application/json' -d '{"query":"{ me { id } }"}'`
- `node -e "console.log('null fields + errors array = partial success')"`
- `curl -s -X POST http://localhost:4000/graphql -H 'Content-Type: application/json' -d '{"query":"{ broken }"}' | python -m json.tool`
- `node -e "const {GraphQLError}=require('graphql');const e=new GraphQLError('Too complex',{extensions:{code:'COMPLEXITY'}});console.log(e.message)"`

**Examples:**
- node -e "const {GraphQLError}=require('graphql');const e=new GraphQLError('Not authorized',{extensions:{code:'UNAUTHENTICATED'}});console.log(e.extensions)"
- curl -s -X POST http://localhost:4000/graphql -H 'Content-Type: application/json' -d '{"query":"{ broken }"}' | python -m json.tool
- curl -s -X POST http://localhost:4000/graphql -H 'Content-Type: application/json' -d '{"query":"{ me { id } }"}'

## References
- [RFC 9457](https://www.rfc-editor.org/rfc/rfc9457)
- [GraphQL Error Spec](https://spec.graphql.org/draft/#sec-Errors)

