Skip to content
This repository was archived by the owner on Sep 12, 2018. It is now read-only.

Commit fb94977

Browse files
author
Olivier Gambier
committed
Cleaner bugsnag abstraction
Docker-DCO-1.1-Signed-off-by: Olivier Gambier <[email protected]> (github: dmp42)
1 parent 0c0ccd4 commit fb94977

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed

docker_registry/app.py

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@
55
import os
66
import sys
77

8-
try:
9-
import bugsnag
10-
import bugsnag.flask
11-
except ImportError as e:
12-
_bugsnag_import_error = e
13-
bugsnag = None
14-
158
from . import toolkit
169
from .lib import config
1710
from .server import __version__
@@ -76,6 +69,22 @@ def after_request(response):
7669
return response
7770

7871

72+
def bugsnag(application, api_key, flavor, version):
73+
# Configure bugsnag
74+
if api_key:
75+
import bugsnag
76+
import bugsnag.flask
77+
78+
root_path = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
79+
bugsnag.configure(api_key=api_key,
80+
project_root=root_path,
81+
release_stage=flavor,
82+
notify_release_stages=[flavor],
83+
app_version=version
84+
)
85+
bugsnag.flask.handle_exceptions(application)
86+
87+
7988
def init():
8089
# Configure the email exceptions
8190
info = cfg.email_exceptions
@@ -96,20 +105,7 @@ def init():
96105
secure=secure_args)
97106
mail_handler.setLevel(logging.ERROR)
98107
app.logger.addHandler(mail_handler)
99-
# Configure bugsnag
100-
info = cfg.bugsnag
101-
if info:
102-
if not bugsnag:
103-
raise _bugsnag_import_error
104-
root_path = os.path.abspath(os.path.join(os.path.dirname(__file__),
105-
'..'))
106-
bugsnag.configure(api_key=info,
107-
project_root=root_path,
108-
release_stage=cfg.flavor,
109-
notify_release_stages=[cfg.flavor],
110-
app_version=__version__
111-
)
112-
bugsnag.flask.handle_exceptions(app)
108+
bugsnag(app, cfg.bugsnag, cfg.flavor, __version__)
113109
# Configure flask_cors
114110
for i in cfg.cors.keys():
115111
app.config['CORS_%s' % i.upper()] = cfg.cors[i]

0 commit comments

Comments
 (0)