Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_auto_notify_defaults(self):
bugsnag.auto_notify(ScaryException("unexpected failover"))
json_body = self.server.received[0]['json_body']
event = json_body['events'][0]
self.assertTrue(event['unhandled'])
self.assertEqual(event['severity'], 'error')
self.assertEqual(event['severityReason'], {
"type": "unhandledException"
})
def test_auto_notify_overrides(self):
bugsnag.auto_notify(
ScaryException("unexpected failover"),
severity='info',
unhandled=False,
severity_reason={
"type": "middleware_handler",
"attributes": {
"name": "test middleware"
}
}
)
json_body = self.server.received[0]['json_body']
event = json_body['events'][0]
self.assertFalse(event['unhandled'])
self.assertEqual(event['severity'], 'info')
self.assertEqual(event['severityReason'], {
def close(self):
try:
if hasattr(self.app, 'close'):
return self.app.close()
except Exception as e:
bugsnag.auto_notify(
e,
severity_reason=self.SEVERITY_REASON
)
raise
finally:
bugsnag.clear_request_config()
def __init__(self, application, environ, start_response):
self.environ = environ
bugsnag.configure_request(wsgi_environ=self.environ)
try:
if bugsnag.configuration.auto_capture_sessions:
bugsnag.start_session()
self.app = application(environ, start_response)
except Exception as e:
bugsnag.auto_notify(
e,
severity_reason=self.SEVERITY_REASON
)
raise
"attributes": {
"framework": "Tornado"
}
}
}
# Notify bugsnag, unless it's an HTTPError that we specifically want
# to ignore
should_notify_bugsnag = True
if type(exc) == HTTPError:
ignore_status_codes = self.bugsnag_ignore_status_codes()
if ignore_status_codes and exc.status_code in ignore_status_codes:
should_notify_bugsnag = False
if should_notify_bugsnag:
bugsnag.auto_notify(exc, **options)
# Call the parent handler
RequestHandler._handle_request_exception(self, exc)
def __log_exception(sender, exception, **extra):
bugsnag.auto_notify(exception, severity_reason={
"type": "unhandledExceptionMiddleware",
"attributes": {
"framework": "Flask"
}
def failure_handler(sender, task_id, exception, args, kwargs, traceback, einfo,
**kw):
task = {
"task_id": task_id,
"args": args,
"kwargs": kwargs
}
bugsnag.auto_notify(exception, traceback=traceback,
context=sender.name,
extra_data=task,
severity_reason={
'type': 'unhandledExceptionMiddleware',
'attributes': {
'framework': 'Celery'
}
def process_exception(self, request, exception):
try:
bugsnag.auto_notify(
exception,
severity_reason={
"type": "unhandledExceptionMiddleware",
"attributes": {
"framework": "Django"
}
}
)
except Exception:
bugsnag.logger.exception("Error in exception middleware")
bugsnag.clear_request_config()
return None