Loading...
Loading...
Compare original and translation side by side
| 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) |
| 方面 | 详情 |
|---|---|
| 输入 | 来自ln-770的上下文存储 |
| 输出 | 异常处理中间件和自定义异常 |
| 技术栈 | .NET (ASP.NET Core Middleware), Python (FastAPI exception handlers) |
STACKFRAMEWORKPROJECT_ROOTENVIRONMENTGlobalExceptionMiddlewareUseExceptionHandler@app.exception_handlerexception_handlers.py{ "status": "skipped" }STACKFRAMEWORKPROJECT_ROOTENVIRONMENTGlobalExceptionMiddlewareUseExceptionHandler@app.exception_handlerexception_handlers.py{ "status": "skipped" }MCP ref: "ASP.NET Core global exception handling middleware"
Context7: /dotnet/aspnetcoreMCP ref: "FastAPI exception handlers custom exceptions"
Context7: /tiangolo/fastapiMCP ref: "ASP.NET Core global exception handling middleware"
Context7: /dotnet/aspnetcoreMCP ref: "FastAPI exception handlers custom exceptions"
Context7: /tiangolo/fastapi| Option | Description |
|---|---|
| ProblemDetails (RFC 7807) (Recommended) | Standardized format, widely adopted |
| Custom Format | Project-specific requirements |
| 选项 | 描述 |
|---|---|
| ProblemDetails (RFC 7807)(推荐) | 标准化格式,被广泛采用 |
| 自定义格式 | 符合项目特定需求 |
| Environment | Stack Trace | Inner Exceptions | Request Details |
|---|---|---|---|
| Development | ✓ Show | ✓ Show | ✓ Show |
| Production | ✗ Hide | ✗ Hide | ✗ Hide |
| 环境 | 堆栈跟踪 | 内部异常 | 请求详情 |
|---|---|---|---|
| 开发环境 | ✓ 显示 | ✓ 显示 | ✓ 显示 |
| 生产环境 | ✗ 隐藏 | ✗ 隐藏 | ✗ 隐藏 |
| Code | HTTP Status | Description |
|---|---|---|
| 400 | Invalid input data |
| 401 | Authentication required |
| 403 | Insufficient permissions |
| 404 | Resource not found |
| 409 | Resource state conflict |
| 500 | Unexpected server error |
| 代码 | HTTP状态码 | 描述 |
|---|---|---|
| 400 | 输入数据无效 |
| 401 | 需要身份验证 |
| 403 | 权限不足 |
| 404 | 资源未找到 |
| 409 | 资源状态冲突 |
| 500 | 服务器意外错误 |
| File | Purpose |
|---|---|
| Exception handling middleware |
| Base exception class |
| Validation errors |
| Not found errors |
| Error response model |
app.UseMiddleware<GlobalExceptionMiddleware>();| 文件 | 用途 |
|---|---|
| 异常处理中间件 |
| 基础异常类 |
| 验证错误类 |
| 资源未找到错误类 |
| 错误响应模型 |
app.UseMiddleware<GlobalExceptionMiddleware>();| File | Purpose |
|---|---|
| Custom exception classes |
| FastAPI exception handlers |
| Pydantic error models |
app.add_exception_handler(AppException, app_exception_handler)
app.add_exception_handler(RequestValidationError, validation_exception_handler)| 文件 | 用途 |
|---|---|
| 自定义异常类 |
| FastAPI异常处理器 |
| 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{
"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"
}dotnet build --no-restorepython -m py_compile exceptions/handlers.py{
"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"
}{
"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"
}