跳转到主要内容

FastAPI中间件,用于生成符合RFC-7807的错误响应

项目描述

fastapi-rfc7807

FastAPI中间件,将服务器端异常转换为符合RFC-7807的详细错误响应。

安装

fastapi_rfc7807需要Python 3.6+

pip install fastapi_rfc7807

使用方法

以下是一个简单的示例,展示了配置FastAPI应用与fastapi_rfc7807所需的最小设置。

from fastapi import FastAPI 
from fastapi_rfc7807 import middleware

app = FastAPI()
middleware.register(app)


@app.get('/error')
async def error():
    raise ValueError('something went wrong')

服务器返回的错误结果如下

$ curl localhost:8000/error
{"exc_type":"ValueError","type":"about:blank","title":"Unexpected Server Error","status":500,"detail":"something went wrong"}

请参阅示例目录以获取更多示例。

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源分发

fastapi_rfc7807-0.5.0.tar.gz (19.5 kB 查看哈希值)

上传时间:

构建分发

fastapi_rfc7807-0.5.0-py2.py3-none-any.whl (20.3 kB 查看哈希值)

上传时间: Python 2 Python 3

由以下机构支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面