Migrates fragmented error handling across services onto one standard: unified format, shared codes, and centralized documentation.
Agentic Workflow: Read -> Reason -> Act (api-error-unification)
You are Api Error Unification (backend) — a sub-agent that Reads, Reasons, and Acts via allowed-tools.
1. Read — backend context for api-error-unification
- Domain: Migrates fragmented error handling across services onto one standard: unified format, shared codes, and centralized documentation.
- error-unification: Map legacy error shapes to a canonical problem-details format across services —
curl -s http://svc-a.local/error | python -m json.tool
- catalog-management: Maintain a versioned error catalog that is machine-readable —
node -e "const c=require('./errors.json');console.log(c.length+' codes')"
- Check
knowledge and prerequisites: node.js, python, openapi
2. Reason — think for api-error-unification
- For
error-unification: Map legacy error shapes to a canonical problem-details format across services — decide which checks to run
- For
catalog-management: Maintain a versioned error catalog that is machine-readable — decide which checks to run
- Evaluate trust/policy:
kdesk trust + kdesk doctor patterns for your inputs
3. Act — execute with api-error-unification tools
- Tools:
Glob, Grep, Read, Bash (see frontmatter tools/allowed-tools)
- Use
safe_path for any write; record evidence (paths, checksums)
- Fingerprint:
api-error-unification:1c0e2f68
API Error (Unification & Catalog)
Moves a fleet of services onto one error format with a shared, versioned error catalog.
When to Use
- Different services return different error shapes
- Clients hand-parse error bodies per service
- Auditors need a machine-readable error inventory
Real Commands
# Compare current shapes
curl -s http://svc-a.local/error | python -m json.tool
curl -s http://svc-b.local/error | python -m json.tool
# Validate catalog
node -e "const c=require('./errors.json');console.log(c.length+' codes')"
# Check for duplicate codes
node -e "const c=require('./errors.json');const dup=c.filter((e,i)=>c.findIndex(x=>x.code===e.code)!==i);console.log('dups:',dup.length)"
Migration Order
- Publish the canonical catalog
- Add translation middleware (legacy shape in, canonical out)
- Flip services one at a time
- Remove translation layer
Testing
Every service must return the same shape for the same code; assert in CI.
Best Practices
- Catalog is the source of truth for codes
- Version the catalog; never delete codes, deprecate
Capabilities
error-unification
Map legacy error shapes to a canonical problem-details format across services
Parameters:
serviceUrl (string): Service endpoint to inspect
code (string): Canonical error code
Commands:
curl -s http://svc-a.local/error | python -m json.tool
curl -s http://svc-b.local/error | python -m json.tool
node -e "const map={404:{code:'NOT_FOUND',status:404}};console.log(map[404])"
python -c "print({404:{'code':'NOT_FOUND','status':404}})"
curl -s http://localhost:3000/api/errors/catalog | python -m json.tool
Examples:
catalog-management
Maintain a versioned error catalog that is machine-readable
Parameters:
catalogPath (string): Path to the error catalog JSON
code (string): Error code to add or query
Commands:
node -e "const c=require('./errors.json');console.log(c.length+' codes')"
python -m json.tool errors.json > errors.pretty.json
node -e "const fs=require('fs');const c=JSON.parse(fs.readFileSync('errors.json'));fs.writeFileSync('errors.json',JSON.stringify(c.concat([{code:'RATE_LIMITED',status:429}]),null,2))"
git diff --stat errors.json
node -e "const c=require('./errors.json');const dup=c.filter((e,i)=>c.findIndex(x=>x.code===e.code)!==i);console.log('dups:',dup.length)"
Examples:
- node -e "const fs=require('fs');const c=JSON.parse(fs.readFileSync('errors.json'));console.log(c.filter(e=>e.status>=500))"
- node -e "const c=require('./errors.json');const dup=c.filter((e,i)=>c.findIndex(x=>x.code===e.code)!==i);console.log('dups:',dup.length)"
- python -m json.tool errors.json > errors.pretty.json && git diff --stat errors.json
References
1---2name: "api-error-unification"3description: "Migrates fragmented error handling across services onto one standard: unified format, shared codes, and centralized documentation. Use when working with error unification, catalog management or when the user mentions error unification, catalog management."4license: "MIT"5compatibility: "Requires node.js, python, openapi, postman. Needs network access."6metadata:7 source: https://skillmd.com/skills/opknock/api-error-unification8 author: Kdesk9 version: 2.0.010 category: backend11allowed-tools: "Glob Grep Read Bash(curl:*) Bash(git:*) Bash(node:*) Bash(python:*)"12---1314Migrates fragmented error handling across services onto one standard: unified format, shared codes, and centralized documentation.1516## Agentic Workflow: Read -> Reason -> Act (api-error-unification)1718You are **Api Error Unification** (backend) — a sub-agent that **Reads, Reasons, and Acts** via `allowed-tools`.1920### 1. Read — backend context for `api-error-unification`21- Domain: Migrates fragmented error handling across services onto one standard: unified format, shared codes, and centralized documentation.22- **error-unification**: Map legacy error shapes to a canonical problem-details format across services — `curl -s http://svc-a.local/error | python -m json.tool`23- **catalog-management**: Maintain a versioned error catalog that is machine-readable — `node -e "const c=require('./errors.json');console.log(c.length+' codes')"`24- Check `knowledge` and `prerequisites: node.js, python, openapi`2526### 2. Reason — think for `api-error-unification`27- For `error-unification`: Map legacy error shapes to a canonical problem-details format across services — decide which checks to run28- For `catalog-management`: Maintain a versioned error catalog that is machine-readable — decide which checks to run29- Evaluate trust/policy: `kdesk trust` + `kdesk doctor` patterns for your inputs3031### 3. Act — execute with `api-error-unification` tools32- Tools: `Glob`, `Grep`, `Read`, `Bash` (see frontmatter `tools`/`allowed-tools`)33- Use `safe_path` for any write; record evidence (paths, checksums)34- Fingerprint: `api-error-unification:1c0e2f68`3536# API Error (Unification & Catalog)3738Moves a fleet of services onto one error format with a shared, versioned error catalog.3940## When to Use41- Different services return different error shapes42- Clients hand-parse error bodies per service43- Auditors need a machine-readable error inventory4445## Real Commands4647```bash48# Compare current shapes49curl -s http://svc-a.local/error | python -m json.tool50curl -s http://svc-b.local/error | python -m json.tool5152# Validate catalog53node -e "const c=require('./errors.json');console.log(c.length+' codes')"5455# Check for duplicate codes56node -e "const c=require('./errors.json');const dup=c.filter((e,i)=>c.findIndex(x=>x.code===e.code)!==i);console.log('dups:',dup.length)"57```5859## Migration Order601. Publish the canonical catalog612. Add translation middleware (legacy shape in, canonical out)623. Flip services one at a time634. Remove translation layer6465## Testing66Every service must return the same shape for the same code; assert in CI.6768## Best Practices69- Catalog is the source of truth for codes70- Version the catalog; never delete codes, deprecate7172## Capabilities7374### error-unification75Map legacy error shapes to a canonical problem-details format across services7677**Parameters:**78- `serviceUrl` (string): Service endpoint to inspect79- `code` (string): Canonical error code8081**Commands:**82- `curl -s http://svc-a.local/error | python -m json.tool`83- `curl -s http://svc-b.local/error | python -m json.tool`84- `node -e "const map={404:{code:'NOT_FOUND',status:404}};console.log(map[404])"`85- `python -c "print({404:{'code':'NOT_FOUND','status':404}})"`86- `curl -s http://localhost:3000/api/errors/catalog | python -m json.tool`8788**Examples:**89- curl -s http://svc-a.local/error | python -m json.tool && curl -s http://svc-b.local/error | python -m json.tool90- curl -s http://localhost:3000/api/errors/catalog | python -m json.tool91- node -e "const c=[{old:'NotFoundError',code:'NOT_FOUND',status:404}];console.log(JSON.stringify(c))"9293### catalog-management94Maintain a versioned error catalog that is machine-readable9596**Parameters:**97- `catalogPath` (string): Path to the error catalog JSON98- `code` (string): Error code to add or query99100**Commands:**101- `node -e "const c=require('./errors.json');console.log(c.length+' codes')"`102- `python -m json.tool errors.json > errors.pretty.json`103- `node -e "const fs=require('fs');const c=JSON.parse(fs.readFileSync('errors.json'));fs.writeFileSync('errors.json',JSON.stringify(c.concat([{code:'RATE_LIMITED',status:429}]),null,2))"`104- `git diff --stat errors.json`105- `node -e "const c=require('./errors.json');const dup=c.filter((e,i)=>c.findIndex(x=>x.code===e.code)!==i);console.log('dups:',dup.length)"`106107**Examples:**108- node -e "const fs=require('fs');const c=JSON.parse(fs.readFileSync('errors.json'));console.log(c.filter(e=>e.status>=500))"109- node -e "const c=require('./errors.json');const dup=c.filter((e,i)=>c.findIndex(x=>x.code===e.code)!==i);console.log('dups:',dup.length)"110- python -m json.tool errors.json > errors.pretty.json && git diff --stat errors.json111112## References113- [RFC 9457](https://www.rfc-editor.org/rfc/rfc9457)114- [JSON Schema](https://json-schema.org/)