Claude-skill-registry Error Shape Taxonomy
Standard error response taxonomy and envelope for services, including error codes, categories, retryability, correlation IDs, safe messaging, and validation error details
install
source · Clone the upstream repo
git clone https://github.com/majiayu000/claude-skill-registry
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/majiayu000/claude-skill-registry "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/data/error-shape-taxonomy" ~/.claude/skills/majiayu000-claude-skill-registry-error-shape-taxonomy && rm -rf "$T"
manifest:
skills/data/error-shape-taxonomy/SKILL.mdsource content
Error Shape Taxonomy
Overview
มาตรฐาน error response format ที่ใช้ทั้งองค์กร ครอบคลุม error codes, categories, และ structure ที่ทำให้ client และ monitoring tools เข้าใจ error ได้ทันที
Why This Matters
- Debuggability: รู้ทันทีว่า error มาจากไหน ทำไม
- Client handling: Frontend/mobile handle errors ได้ถูกต้อง
- Monitoring: Alert และ dashboard แยก error types ได้
- Documentation: Error catalog ที่ reference ได้
Core Concepts
1. Error Envelope Structure
- แนะนำให้ยึดแนวคิด RFC 7807 (problem details) แต่ให้คงโครงเดียวกันทั้งองค์กร
- ต้องมี:
,code
,message
,requestId
,timestampstatus - ถ้าเป็น retryable ให้มี
และretryable
(ถ้ามี)retryAfterSeconds
2. Error Code System
หรือPREFIX_###
(อ่านง่าย, stable)PREFIX_SUB_###- code ต้อง คงที่ (ห้ามเปลี่ยนความหมาย) และต้อง document ใน catalog
- หลีกเลี่ยงใช้ HTTP status เป็น code (เช่น
) เพราะไม่สื่อสาเหตุERR_500
3. Error Categories
กำหนดหมวดให้ชัดเพื่อ routing/alert:
/AUTH_
: authn/authzAUTHZ_
: validation / malformed requestsVAL_
: business/domain rulesBIZ_
: rate limiting / quotasRATE_
: infra/system dependencies (DB, queue, upstream)SYS_
4. Error Messages
ต้องเป็น user-safe (ไม่เปิดเผย stacktrace/SQL/secret)message- รายละเอียดเชิงเทคนิคให้ใส่ใน
(และต้อง scrub PII/secret)details - ถ้าต้องการข้อความที่ UI แสดง ให้มี
แยก (optional) และรองรับ i18nuserMessage
5. Error Context
- ทุก error ต้องมี
(correlation) และควรมีrequestId
ถ้ามี tracingtraceId
และpath
ช่วย debug ได้เร็ว (optional)method- stacktrace ห้ามส่งกลับ client; ให้เก็บใน logs เท่านั้น
6. Localization
- ถ้ารองรับหลายภาษา: client ใช้
และ server map เป็นAccept-LanguageuserMessage - ไม่ควร encode ภาษาไว้ใน
(code ควรเป็นภาษากลาง)code
7. Error Mapping
- map internal errors → external errors แบบ deterministic และทดสอบได้
- errors จาก upstream ต้อง normalize เข้าสู่ shape มาตรฐานของเรา
ต้องสะท้อน semantics (เช่นstatus
ส่วนใหญ่เป็นVAL_
)400/422
8. Error Documentation
- มี “error catalog” ต่อ service หรือองค์กร:
,code
,status
,meaning
,client actionretryable - ใช้เป็นแหล่งข้อมูลสำหรับ client SDK, docs, และ alert routing
Quick Start
export type ErrorCategory = "AUTH" | "AUTHZ" | "VAL" | "BIZ" | "RATE" | "SYS"; export interface ErrorResponse { error: { code: string; category: ErrorCategory; message: string; status: number; requestId: string; timestamp: string; path?: string; method?: string; retryable?: boolean; retryAfterSeconds?: number; details?: Record<string, unknown>; validationErrors?: Array<{ field: string; reason: string }>; }; }
Production Checklist
- All errors follow standard shape
- Error codes documented in catalog
- User-safe messages (no sensitive data)
- Request ID included in all errors
- Error logging consistent
Standard Error Shape
// Example payload (VAL_) // { // "error": { // "code": "VAL_001", // "category": "VAL", // "message": "Invalid request", // "status": 422, // "requestId": "req-789", // "timestamp": "2024-01-15T10:00:00Z", // "validationErrors": [ // { "field": "email", "reason": "Invalid email format" } // ] // } // }
Error Code Taxonomy
| Prefix | Category | Example |
|---|---|---|
| AUTH_ | Authentication | AUTH_001 Token expired |
| AUTHZ_ | Authorization | AUTHZ_001 Permission denied |
| VAL_ | Validation | VAL_001 Invalid email format |
| BIZ_ | Business logic | BIZ_001 Insufficient balance |
| SYS_ | System | SYS_001 Database unavailable |
| RATE_ | Rate limiting | RATE_001 Too many requests |
Status + Retryability Guidelines
: ไม่ควร retry แบบอัตโนมัติ (ต้องแก้ credential/permission)401/403
: ไม่ควร retry (ต้องแก้ request)400/422
: retry ได้ในบางกรณี (ใช้ backoff) ถ้าเป็น conflict ชั่วคราว409
: retry ได้ โดยใช้429Retry-After
: retry ได้ (bounded retries + jitter)503/504
Anti-patterns
- Generic errors: "Something went wrong"
- Leaking internals: Stack traces to client
- Inconsistent shape: Different format per service
- Missing correlation: No request ID
- Changing meaning: เปลี่ยน semantics ของ code เดิม ทำให้ client/alert พัง
Integration Points
- API gateways (error transformation)
- Frontend error boundaries
- Monitoring/alerting
- Documentation generators