Permalink
Browse files

Changed Flask support to use got_request_exception

  • Loading branch information...
1 parent 649ed70 commit 4977828e8e2527c709495a28816617a14c8914d8 @dcramer dcramer committed Oct 7, 2011
Showing with 22 additions and 18 deletions.
  1. +19 −17 raven/contrib/flask/__init__.py
  2. +2 −1 raven/middleware.py
  3. +1 −0 setup.py
@@ -9,39 +9,41 @@
from __future__ import absolute_import
from flask import request
+from flask.signals import got_request_exception
from raven.base import Client
class Sentry(object):
def __init__(self, app=None, client=None, client_cls=Client):
self.app = app
self.client = client
self.client_cls = client_cls
+
if app:
self.init_app(app)
+ def handle_exception(self, client):
+ def _handle_exception(sender, **kwargs):
+ client.create_from_exception(
+ url=request.url,
+ data={
+ 'META': request.environ,
+ 'GET': request.args,
+ 'POST': request.form,
+ 'app': sender.name,
+ },
+ )
+ return _handle_exception
+
def init_app(self, app):
- self.app = app
- app.error_handler_spec[None][500] = self.handle_exception
if not self.client:
- self.client = self.client_cls(
+ client = self.client_cls(
include_paths=app.config.get('SENTRY_INCLUDE_PATHS'),
exclude_paths=app.config.get('SENTRY_EXCLUDE_PATHS'),
remote_urls=app.config.get('SENTRY_REMOTE_URLS'),
name=app.config.get('SENTRY_NAME'),
key=app.config.get('SENTRY_KEY'),
)
+ else:
+ client = self.client
- def handle_exception(self, error):
- if not self.client:
- return
-
- event_id = self.client.create_from_exception(
- url=request.url,
- data={
- 'META': request.environ,
- 'GET': request.args,
- 'POST': request.form,
- },
- )
- # TODO: this should be handled by the parent application
- return 'An unknown error occurred', 500
+ got_request_exception.connect(self.handle_exception(client), sender=app, weak=False)
View
@@ -20,7 +20,8 @@ def __init__(self, application, client):
def __call__(self, environ, start_response):
try:
- return self.application(environ, start_response)
+ for event in self.application(environ, start_response):
+ yield event
except Exception:
exc_info = sys.exc_info()
self.handle_exception(exc_info, environ)
View
@@ -14,6 +14,7 @@
'django-celery',
'celery',
+ 'blinker>=1.1',
'Flask>=0.8',
'django-sentry',
'django-nose',

0 comments on commit 4977828

Please sign in to comment.