Sentry-python: Flask-Restful: 405 method not allowed and other HTTP exceptions sent to server

Created on 9 Mar 2019  路  3Comments  路  Source: getsentry/sentry-python

When I use Flask-Restful in combination with the FlaskIntegration(), the SDK will report 405 Method Not Allowed and other HTTP-related exceptions to the server, even though we don't intend to. This issue does not occur with Flask's own MethodView or the regular function-based routes.

I consider this a bug in Flask-Restful. This is just a tracking issue for https://github.com/flask-restful/flask-restful/issues/802.

The workaround for this is to filter out http exceptions like any other exception:

from werkzeug.exceptions import HTTPException

def before_send(event, hint):
    if 'exc_info' in hint:
        exc_type, exc_value, tb = hint['exc_info']
        if isinstance(exc_value, HTTPException):
            return None
    return event

sentry_sdk.init(before_send=before_send)
bug

Most helpful comment

I'm hesitant in marking this as wontfix, we should probably ship a workaround for this if many people are affected. Sadly this would mean that there's no exact correlation between Flask's own notion of "unhandled exception" and ours.

All 3 comments

I'm hesitant in marking this as wontfix, we should probably ship a workaround for this if many people are affected. Sadly this would mean that there's no exact correlation between Flask's own notion of "unhandled exception" and ours.

A simpler workaround

from werkzeug.exceptions import HTTPException

sentry_sdk.init(
    ignore_errors=[HTTPException],  # workaround to ignore abort() on inside flask-restful
)

@bertonha We didn't stabilize ignore_errors yet, see #149. But yes, this is shorter and works too.

Was this page helpful?
0 / 5 - 0 ratings