ln-772-error-handler-setup

Configures global exception handling middleware. Use when adding centralized error handling to .NET or Python backends.

310 stars

Best use case

ln-772-error-handler-setup is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Configures global exception handling middleware. Use when adding centralized error handling to .NET or Python backends.

Teams using ln-772-error-handler-setup 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

$curl -o ~/.claude/skills/ln-772-error-handler-setup/SKILL.md --create-dirs "https://raw.githubusercontent.com/levnikolaevich/claude-code-skills/main/skills-catalog/ln-772-error-handler-setup/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/ln-772-error-handler-setup/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How ln-772-error-handler-setup Compares

Feature / Agentln-772-error-handler-setupStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Configures global exception handling middleware. Use when adding centralized error handling to .NET or Python backends.

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

# ln-772-error-handler-setup

**Type:** L3 Worker
**Category:** 7XX Project Bootstrap

Configures global error handling for .NET and Python backend applications.

---

## Overview

| Aspect | Details |
|--------|---------|
| **Input** | Context Store from ln-770 |
| **Output** | Exception handling middleware and custom exceptions |
| **Stacks** | .NET (ASP.NET Core Middleware), Python (FastAPI exception handlers) |

---

## Phase 1: Receive Context

Accept Context Store from coordinator.

**Required Context:**
- `STACK`: .NET or Python
- `FRAMEWORK`: ASP.NET Core or FastAPI
- `PROJECT_ROOT`: Project directory path
- `ENVIRONMENT`: Development or Production

**Idempotency Check:**
- .NET: Grep for `GlobalExceptionMiddleware` or `UseExceptionHandler`
- Python: Grep for `@app.exception_handler` or `exception_handlers.py`
- If found: Return `{ "status": "skipped" }`

---

## Phase 2: Research Error Handling Patterns

Use MCP tools to get up-to-date documentation.

**For .NET:**
```
MCP ref: "ASP.NET Core global exception handling middleware"
Context7: /dotnet/aspnetcore
```

**For Python:**
```
MCP ref: "FastAPI exception handlers custom exceptions"
Context7: /tiangolo/fastapi
```

**Key Patterns to Research:**
1. Middleware pipeline positioning
2. Exception type mapping to HTTP status codes
3. ProblemDetails (RFC 7807) format
4. Development vs Production error details
5. Logging integration

---

## Phase 3: Decision Points

### Q1: Error Response Format

| Option | Description |
|--------|-------------|
| **ProblemDetails (RFC 7807)** (Recommended) | Standardized format, widely adopted |
| **Custom Format** | Project-specific requirements |

### Q2: Error Detail Level

| Environment | Stack Trace | Inner Exceptions | Request Details |
|-------------|-------------|------------------|-----------------|
| Development | ✓ Show | ✓ Show | ✓ Show |
| Production | ✗ Hide | ✗ Hide | ✗ Hide |

### Q3: Error Taxonomy

Define standard error codes:

| Code | HTTP Status | Description |
|------|-------------|-------------|
| `VALIDATION_ERROR` | 400 | Invalid input data |
| `UNAUTHORIZED` | 401 | Authentication required |
| `FORBIDDEN` | 403 | Insufficient permissions |
| `NOT_FOUND` | 404 | Resource not found |
| `CONFLICT` | 409 | Resource state conflict |
| `INTERNAL_ERROR` | 500 | Unexpected server error |

---

## Phase 4: Generate Configuration

### .NET Output Files

| File | Purpose |
|------|---------|
| `Middleware/GlobalExceptionMiddleware.cs` | Exception handling middleware |
| `Exceptions/AppException.cs` | Base exception class |
| `Exceptions/ValidationException.cs` | Validation errors |
| `Exceptions/NotFoundException.cs` | Not found errors |
| `Models/ErrorResponse.cs` | Error response model |

**Generation Process:**
1. Use MCP ref to get current ASP.NET Core exception handling patterns
2. Generate GlobalExceptionMiddleware with:
   - Exception type to HTTP status mapping
   - Logging of exceptions
   - ProblemDetails response format
   - Environment-aware detail level
3. Generate custom exception classes

**Registration Code:**
```csharp
app.UseMiddleware<GlobalExceptionMiddleware>();
```

### Python Output Files

| File | Purpose |
|------|---------|
| `exceptions/app_exceptions.py` | Custom exception classes |
| `exceptions/handlers.py` | FastAPI exception handlers |
| `models/error_response.py` | Pydantic error models |

**Generation Process:**
1. Use MCP ref to get current FastAPI exception handling patterns
2. Generate exception handlers with:
   - HTTPException handling
   - Custom AppException handling
   - Validation error handling
   - Request validation error handling
3. Generate custom exception classes

**Registration Code:**
```python
app.add_exception_handler(AppException, app_exception_handler)
app.add_exception_handler(RequestValidationError, validation_exception_handler)
```

---

## Phase 5: Validate

**Validation Steps:**

1. **Syntax check:**
   - .NET: `dotnet build --no-restore`
   - Python: `python -m py_compile exceptions/handlers.py`

2. **Test error handling:**
   - Create test endpoint that throws exception
   - Verify error response format
   - Check that stack trace hidden in Production

**Expected Error Response (ProblemDetails):**
```json
{
  "type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
  "title": "Validation Error",
  "status": 400,
  "detail": "Invalid input data",
  "instance": "/api/users",
  "errors": [
    { "field": "email", "message": "Invalid email format" }
  ],
  "traceId": "abc-123-def-456"
}
```

---

## Return to Coordinator

```json
{
  "status": "success",
  "files_created": [
    "Middleware/GlobalExceptionMiddleware.cs",
    "Exceptions/AppException.cs",
    "Models/ErrorResponse.cs"
  ],
  "packages_added": [],
  "registration_code": "app.UseMiddleware<GlobalExceptionMiddleware>();",
  "message": "Configured global exception handling"
}
```

---

## Reference Links

- [ASP.NET Core Error Handling](https://learn.microsoft.com/aspnet/core/web-api/handle-errors)
- [FastAPI Handling Errors](https://fastapi.tiangolo.com/tutorial/handling-errors/)
- [RFC 7807 Problem Details](https://tools.ietf.org/html/rfc7807)

---

## Critical Rules

- **Use ProblemDetails (RFC 7807) by default** — standardized error response format
- **Hide stack traces in Production** — environment-aware detail level is mandatory
- **Use MCP ref for current patterns** — do not hardcode middleware from memory
- **Idempotent** — if `GlobalExceptionMiddleware` or `exception_handlers.py` exists, return `status: "skipped"`
- **Map all custom exceptions to HTTP status codes** — no unhandled exception types reaching the client

## Definition of Done

- [ ] Context Store received (stack, framework, environment)
- [ ] Error handling patterns researched via MCP tools
- [ ] GlobalExceptionMiddleware generated (.NET) or exception handlers generated (Python)
- [ ] Custom exception classes created (AppException, ValidationException, NotFoundException)
- [ ] Error response model created (ProblemDetails format)
- [ ] Syntax validated (`dotnet build` or `py_compile`)
- [ ] Structured JSON response returned to ln-770 coordinator

---

**Version:** 2.0.0
**Last Updated:** 2026-01-10

Related Skills

ln-774-healthcheck-setup

310
from levnikolaevich/claude-code-skills

Configures health check endpoints for Kubernetes readiness/liveness/startup probes. Use when deploying to Kubernetes.

ln-770-crosscutting-setup

310
from levnikolaevich/claude-code-skills

Sets up logging, error handling, CORS, health checks, and API docs. Use when adding cross-cutting concerns to backend projects.

ln-760-security-setup

310
from levnikolaevich/claude-code-skills

Sets up security scanning for secrets and dependency vulnerabilities. Use when adding security infrastructure to a project.

ln-742-precommit-setup

310
from levnikolaevich/claude-code-skills

Configures Husky, lint-staged, commitlint, and Python pre-commit hooks. Use when adding Git hook automation to a project.

ln-740-quality-setup

310
from levnikolaevich/claude-code-skills

Sets up linters, pre-commit hooks, and test infrastructure. Use when adding code quality tooling to a project.

ln-730-devops-setup

310
from levnikolaevich/claude-code-skills

Sets up Docker, CI/CD, and environment configuration with auto-detection. Use when adding DevOps infrastructure to a project.

ln-010-dev-environment-setup

310
from levnikolaevich/claude-code-skills

Installs agents, configures MCP servers, syncs configs, creates and audits instructions. Use after setup or when agents/MCP need alignment.

ln-914-community-responder

310
from levnikolaevich/claude-code-skills

Responds to unanswered GitHub discussions and issues with codebase-informed replies. Use when clearing community question backlog.

ln-913-community-debater

310
from levnikolaevich/claude-code-skills

Launches RFC and debate discussions on GitHub. Use when proposing changes that need community input or voting.

ln-912-community-announcer

310
from levnikolaevich/claude-code-skills

Composes and publishes announcements to GitHub Discussions. Use when sharing releases, updates, or news with the community.

ln-911-github-triager

310
from levnikolaevich/claude-code-skills

Produces prioritized triage report from open GitHub issues, PRs, and discussions. Use when reviewing community backlog.

ln-910-community-engagement

310
from levnikolaevich/claude-code-skills

Analyzes community health and delegates engagement tasks. Use when managing GitHub issues, discussions, and announcements.