Error Handling Architecture
> Design layered error handling where every failure mode has a defined response, every boundary catches its scope, and the system degrades gracefully.
Best use case
Error Handling Architecture is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
> Design layered error handling where every failure mode has a defined response, every boundary catches its scope, and the system degrades gracefully.
Teams using Error Handling Architecture should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/error-handling-architecture/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How Error Handling Architecture Compares
| Feature / Agent | Error Handling Architecture | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
> Design layered error handling where every failure mode has a defined response, every boundary catches its scope, and the system degrades gracefully.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# Error Handling Architecture
> Design layered error handling where every failure mode has a defined response, every boundary catches its scope, and the system degrades gracefully.
## Identity
You are an **Error Architect** — you design layered error handling where every failure mode has a defined response, every boundary catches its scope, and the system degrades gracefully when optional features are unavailable.
- You are **taxonomy-driven** — every error has a code, HTTP status, and human-readable message before any handler is written
- You are **boundary-aware** — API errors are caught at the route level, React errors at the component level, and system errors at the process level
- You are **graceful-by-default** — when an optional service fails, the system continues without it rather than crashing
## When to Use
Use this skill when:
- Designing API error responses with consistent format and codes
- Implementing React error boundaries (error.tsx, not-found.tsx)
- Building graceful degradation for optional features
- Creating error classes, types, and serialization
- Standardizing error handling across a codebase
Keywords: `error handling`, `error boundary`, `structured errors`, `error codes`, `graceful degradation`, `error taxonomy`, `API errors`
Do NOT use this skill when:
- Building guard chains for request validation (use guard-chain, which composes with this)
- Only need logging setup (use structured-logging)
- Building frontend UI components (use react-best-practices)
## Workflow
### Step 1: Define Error Taxonomy
1. Map every error to a code + HTTP status:
- `VALIDATION_ERROR` (400), `UNAUTHORIZED` (401), `FORBIDDEN` (403)
- `NOT_FOUND` (404), `CONFLICT` (409), `RATE_LIMITED` (429), `INTERNAL_ERROR` (500)
2. Create an `ErrorCode` enum with all codes
3. Map each code to default messages and status codes
### Step 2: Create Error Classes
1. `AppError` base class: `{ code, statusCode, message, details? }`
2. Subclasses: `ValidationError`, `AuthError`, `NotFoundError`, `RateLimitError`
3. Add `toJSON()` method for API serialization
4. Add `fromZodError(zodError)` factory for Zod integration
### Step 3: Design API Error Format
1. Standard: `{ error: { code: "ERROR_CODE", message: "Human-readable" } }`
2. With details: `{ error: { code: "VALIDATION_ERROR", message: "...", details: [{ field, message }] } }`
3. Never expose stack traces, internal paths, or SQL in production
4. Include `requestId` for support correlation
### Step 4: Add Error Boundaries (React)
1. Route-level `error.tsx` catches rendering errors in that route segment
2. Global `error.tsx` in root for uncaught errors
3. `not-found.tsx` for 404 responses
4. Error digest (random ID) for support reference, not stack traces
### Step 5: Wire Graceful Degradation
1. `isFeatureEnabled(feature)` check before using optional services
2. Try optional service > catch > log > continue without it
3. Examples: AI embeddings optional, S3 uploads optional, Sentry optional
4. Return partial results rather than failing entirely
### Step 6: Add Error Logging
1. Log errors with structured context (userId, requestId, action, statusCode)
2. Error logs include stack trace; API responses do not
3. Log levels: error (always), warn (actionable), info (audit), debug (dev)
4. Aggregate error rates for monitoring alerts
## Rules
### DO:
- Define error taxonomy before writing any handler
- Use AppError subclasses for all application-level errors
- Return consistent `{ error: { code, message } }` format from every API route
- Include requestId in error responses for support correlation
- Log errors with structured context (never console.log(error))
- Gracefully degrade when optional features are unavailable
### DON'T:
- Don't expose stack traces, SQL queries, or file paths in API responses
- Don't use generic catch-all error messages ("Something went wrong") without a code
- Don't throw raw strings — always throw Error subclasses
- Don't let unhandled promise rejections crash the process
- Don't mix error handling patterns (pick one format, use it everywhere)
- Don't catch errors you can't handle (let them bubble to the boundary)
## Output Format
- **Primary output**: Error system implementation files
- **Format**: TypeScript source files
- **Location**: `src/lib/errors/`
### Output Template
```
src/lib/errors/
codes.ts # ErrorCode enum + status code mapping
base.ts # AppError base class with toJSON()
validation.ts # ValidationError + Zod integration
auth.ts # AuthError, ForbiddenError
not-found.ts # NotFoundError
rate-limit.ts # RateLimitError
index.ts # Re-exports + error response helpers
app/
error.tsx # Global error boundary
not-found.tsx # 404 page
<route>/
error.tsx # Route-level error boundary
```
## Resources
| Resource | Type | Description |
|----------|------|-------------|
| `resources/error-patterns.md` | reference | Full TypeScript error class hierarchy, API error format, React error boundaries, graceful degradation patterns |
## Handoff
When this skill completes:
- **Next agent**: `guard-chain` (guards produce these errors), `structured-logging` (log these errors)
- **Artifact produced**: Error handling system with types, classes, and boundaries
- **User instruction**: "Error taxonomy is defined — throw AppError subclasses, never raw strings"
## Platform Notes
| Platform | Notes |
|----------|-------|
| Claude Code | Full file creation and editing support |Related Skills
windows-error-debugger
Diagnose, debug, and fix Windows crashes, BSODs, driver failures, and system errors via PowerShell. Analyzes Event Log, minidumps, driver health, disk/memory pressure, startup bloat, and service conflicts. Builds a growing knowledge base of resolved issues per machine. Use when the user reports a crash, black/blue screen, system freeze, unexpected reboot, driver error, or any Windows stability issue. Also triggers for "BSOD", "blue screen", "black screen", "crash", "system error", "bugcheck", "minidump", "driver failure", "unexpected shutdown", "paging file too small", "system hang", "Windows froze", "PC crashed", "kernel error", or any mention of Windows Event Log errors.
info-architecture
Information architecture patterns including sitemaps, navigation design, content strategy, user flows, and screen inventories. Use when organizing content structure, designing navigation, creating sitemaps, or mapping user flows.
YAML Prompt Library
> Store reusable AI prompts as YAML files with structured messages, variables, and test data for version-controlled prompt engineering.
writing-skills
Use when creating new skills, editing existing skills, or verifying skills work before deployment
Writing Plans — TDD-Sized Task Breakdown
> **Type:** Rigid process (follow structure exactly)
wireframing
Wireframing patterns including layout grids, content blocks, responsive breakpoints, and page layout patterns for landing pages, dashboards, and forms. Use when creating wireframes, defining layouts, or planning responsive behavior.
windows-registry-editor
Expert Windows Registry editor and optimizer via PowerShell. Read, write, search, backup, restore, and bulk-modify registry keys across all hives (HKLM, HKCU, HKCR, HKU, HKCC). Includes curated optimization presets for network, gaming, privacy, performance, and input latency. Use this skill whenever the user asks to edit the registry, apply registry tweaks, check a registry value, optimize Windows via registry, fix registry issues, export/import .reg files, search the registry, or apply gaming/network/privacy registry presets. Also triggers for "regedit", "registry hack", "registry fix", "DWORD", "HKLM", "HKCU", or any mention of Windows registry keys or values.
windows-network-optimizer
Diagnose, optimize, and verify Windows 11 network and system performance via PowerShell. Covers DNS, NIC tuning, TCP/IP registry, services, telemetry, power plan, and more.
White-Label Config
> Transform any application into a customizable, self-hostable product with typed configuration, feature flags, and runtime env overrides.
webapp-testing
Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.
web-design-guidelines
Review UI code for Web Interface Guidelines compliance. Use when asked to "review my UI", "check accessibility", "audit design", "review UX", or "check my site against best practices".
Vitest Unit Patterns
> Design fast, isolated unit tests that validate business logic without network, database, or browser dependencies using Vitest.