ln-772-error-handler-setup by levnikolaevich/claude-code-skills
npx skills add https://github.com/levnikolaevich/claude-code-skills --skill ln-772-error-handler-setup类型: L3 Worker 类别: 7XX 项目引导 父级: ln-770-crosscutting-setup
为 .NET 和 Python 后端应用程序配置全局错误处理。
| 方面 | 详情 |
|---|---|
| 输入 | 来自 ln-770 的上下文存储 |
| 输出 | 异常处理中间件和自定义异常 |
| 技术栈 | .NET (ASP.NET Core 中间件), Python (FastAPI 异常处理器) |
从协调器接收上下文存储。
所需上下文:
STACK: .NET 或 PythonFRAMEWORK: ASP.NET Core 或 FastAPIPROJECT_ROOT: 项目目录路径广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
ENVIRONMENT: 开发环境或生产环境幂等性检查:
GlobalExceptionMiddleware 或 UseExceptionHandler@app.exception_handler 或 exception_handlers.py{ "status": "skipped" }使用 MCP 工具获取最新的文档。
对于 .NET:
MCP ref: "ASP.NET Core global exception handling middleware"
Context7: /dotnet/aspnetcore
对于 Python:
MCP ref: "FastAPI exception handlers custom exceptions"
Context7: /tiangolo/fastapi
需要研究的关键模式:
| 选项 | 描述 |
|---|---|
| ProblemDetails (RFC 7807) (推荐) | 标准化格式,广泛采用 |
| 自定义格式 | 项目特定要求 |
| 环境 | 堆栈跟踪 | 内部异常 | 请求详情 |
|---|---|---|---|
| 开发环境 | ✓ 显示 | ✓ 显示 | ✓ 显示 |
| 生产环境 | ✗ 隐藏 | ✗ 隐藏 | ✗ 隐藏 |
定义标准错误码:
| 代码 | HTTP 状态 | 描述 |
|---|---|---|
VALIDATION_ERROR | 400 | 无效的输入数据 |
UNAUTHORIZED | 401 | 需要身份验证 |
FORBIDDEN | 403 | 权限不足 |
NOT_FOUND | 404 | 资源未找到 |
CONFLICT | 409 | 资源状态冲突 |
INTERNAL_ERROR | 500 | 意外的服务器错误 |
| 文件 | 用途 |
|---|---|
Middleware/GlobalExceptionMiddleware.cs | 异常处理中间件 |
Exceptions/AppException.cs | 基础异常类 |
Exceptions/ValidationException.cs | 验证错误 |
Exceptions/NotFoundException.cs | 未找到错误 |
Models/ErrorResponse.cs | 错误响应模型 |
生成过程:
注册代码:
app.UseMiddleware<GlobalExceptionMiddleware>();
| 文件 | 用途 |
|---|---|
exceptions/app_exceptions.py | 自定义异常类 |
exceptions/handlers.py | FastAPI 异常处理器 |
models/error_response.py | Pydantic 错误模型 |
生成过程:
注册代码:
app.add_exception_handler(AppException, app_exception_handler)
app.add_exception_handler(RequestValidationError, validation_exception_handler)
验证步骤:
dotnet build --no-restorepython -m py_compile exceptions/handlers.py预期的错误响应 (ProblemDetails):
{
"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"
}
{
"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"
}
GlobalExceptionMiddleware 或 exception_handlers.py 存在,返回 status: "skipped"dotnet build 或 py_compile)版本: 2.0.0 最后更新: 2026-01-10
每周安装量
153
仓库
GitHub 星标
245
首次出现
Jan 24, 2026
安全审计
安装于
claude-code138
cursor136
codex135
gemini-cli135
opencode135
github-copilot130
Type: L3 Worker Category: 7XX Project Bootstrap Parent: ln-770-crosscutting-setup
Configures global error handling for .NET and Python backend applications.
| 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) |
Accept Context Store from coordinator.
Required Context:
STACK: .NET or PythonFRAMEWORK: ASP.NET Core or FastAPIPROJECT_ROOT: Project directory pathENVIRONMENT: Development or ProductionIdempotency Check:
GlobalExceptionMiddleware or UseExceptionHandler@app.exception_handler or exception_handlers.py{ "status": "skipped" }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:
| Option | Description |
|---|---|
| ProblemDetails (RFC 7807) (Recommended) | Standardized format, widely adopted |
| Custom Format | Project-specific requirements |
| Environment | Stack Trace | Inner Exceptions | Request Details |
|---|---|---|---|
| Development | ✓ Show | ✓ Show | ✓ Show |
| Production | ✗ Hide | ✗ Hide | ✗ Hide |
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 |
| 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:
Registration Code:
app.UseMiddleware<GlobalExceptionMiddleware>();
| File | Purpose |
|---|---|
exceptions/app_exceptions.py | Custom exception classes |
exceptions/handlers.py | FastAPI exception handlers |
models/error_response.py | Pydantic error models |
Generation Process:
Registration Code:
app.add_exception_handler(AppException, app_exception_handler)
app.add_exception_handler(RequestValidationError, validation_exception_handler)
Validation Steps:
Syntax check:
dotnet build --no-restorepython -m py_compile exceptions/handlers.pyTest error handling:
Expected Error Response (ProblemDetails):
{
"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"
}
{
"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"
}
GlobalExceptionMiddleware or exception_handlers.py exists, return status: "skipped"dotnet build or py_compile)Version: 2.0.0 Last Updated: 2026-01-10
Weekly Installs
153
Repository
GitHub Stars
245
First Seen
Jan 24, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
claude-code138
cursor136
codex135
gemini-cli135
opencode135
github-copilot130
Python图像处理技能:Pillow脚本生成,支持调整大小、格式转换、网页优化
806 周安装
INTERNAL_ERROR | 500 | Unexpected server error |