-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.py
44 lines (33 loc) · 1.15 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from flask import Flask, jsonify
from api.dashboard import dashboard_api
from api.enrich import enrich_api
from api.health import health_api
from api.respond import respond_api
from api.version import version_api
from api.errors import TRFormattedError
from api.utils import jsonify_errors
app = Flask(__name__)
app.url_map.strict_slashes = False
app.config.from_object('config.Config')
app.register_blueprint(dashboard_api)
app.register_blueprint(enrich_api)
app.register_blueprint(health_api)
app.register_blueprint(respond_api)
app.register_blueprint(version_api)
@app.errorhandler(Exception)
def handle_error(exception):
app.logger.error(exception)
code = getattr(exception, 'code', 500)
message = getattr(exception, 'description', 'Something went wrong.')
reason = '.'.join([
exception.__class__.__module__,
exception.__class__.__name__,
])
response = jsonify(code=code, message=message, reason=reason)
return response, code
@app.errorhandler(TRFormattedError)
def handle_tr_formatted_error(exception):
app.logger.error(exception)
return jsonify_errors(exception.json)
if __name__ == '__main__':
app.run()