跳至主要内容

Sanic错误处理程序,与Sentry集成

项目描述

Travis PyPI

Sentry错误处理程序,用于Sanic网络服务器

需求

  • python >= 3.5

安装

sanic-sentry-error-handler 应使用pip安装

pip install sanic-sentry-error-handler

用法

SENTRY_DSN - 应用程序的Sentry DSN

首先,我们将设置一个Sanic应用程序

>>> from sanic import Sanic
>>> from sanic_sentry import SanicSentryErrorHandler
>>> app = Sanic(__name__)
>>> app.error_handler = SanicSentryErrorHandler('http://public:secret@example.com/1')

如果您的应用程序使用Sanic异常处理视图,您可能考虑使用装饰器来拦截异常。

>>> from sanic import response, Sanic
>>> from sanic_sentry import SanicSentryErrorHandler
>>>
>>> sentry_client = SanicSentryErrorHandler('http://public:secret@example.com/1')
>>> app = Sanic(__name__)
>>>
>>>
>>> @app.exception([Exception, ])
>>> @sentry_client.intercept_exception
>>> def handle_exception_500(request, exception):
>>>     return response.json({"description": "Internal Server Error"}, status=500)

项目详情


下载文件

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

源分发

sanic-sentry-error-handler-0.1.7.tar.gz (2.9 kB 查看哈希值)

上传于

支持者