-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
42 lines (30 loc) · 1.02 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
from flask import Flask, jsonify, g
from api.enrich import enrich_api
from api.health import health_api
from api.respond import respond_api
from api.errors import TRFormattedError
from api.utils import jsonify_result
app = Flask(__name__)
app.url_map.strict_slashes = False
app.config.from_object('config.Config')
app.register_blueprint(health_api)
app.register_blueprint(enrich_api)
app.register_blueprint(respond_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(error):
app.logger.error(error.json)
g.errors = [error.json]
return jsonify_result()
if __name__ == '__main__':
app.run()