Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def tearDown(self):
super(HandlersTest, self).tearDown()
bugsnag.logger.setLevel(logging.CRITICAL)
import logging
import bugsnag
logging.getLogger('requests').setLevel(logging.CRITICAL)
bugsnag.logger.setLevel(logging.CRITICAL)
def setUp(self):
super(HandlersTest, self).setUp()
bugsnag.configure(use_ssl=False,
endpoint=self.server.address,
api_key='tomatoes',
notify_release_stages=['dev'],
release_stage='dev',
asynchronous=False)
bugsnag.logger.setLevel(logging.INFO)
if notification.api_key is None:
bugsnag.logger.warning(
"No API key configured, couldn't notify")
return
if initial_severity != notification.severity:
notification.severity_reason = {
'type': 'userCallbackSetSeverity'
}
else:
notification.severity_reason = initial_reason
payload = notification._payload()
try:
self.configuration.delivery.deliver(self.configuration,
payload)
except Exception as e:
bugsnag.logger.exception('Notifying Bugsnag failed %s', e)
# Trigger session delivery
self.session_tracker.send_sessions()
# the last step in the notification stack is to call the callback.
# we also do this inside the exception handler, so need to ensure that
# the callback is only called once.
def finish(notification):
if not hasattr(finish, 'called'):
finish.called = True
callback()
to_call = finish
for middleware in reversed(self.stack):
to_call = middleware(to_call)
try:
to_call(notification)
except Exception:
bugsnag.logger.exception('Error in exception middleware')
# still notify if middleware crashes before notification
finish(notification)
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