-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
46 lines (35 loc) · 1.14 KB
/
main.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
45
46
import os
from flask_compress import Compress
from flask import Flask, current_app, jsonify
from flask_cors import CORS
from controller.data_controller import data_controller
from util.custom_json_encoder import CustomJSONEncoder
COMPRESS_MIMETYPES = ['text/html', 'text/css', 'text/xml', 'application/json', 'application/javascript']
COMPRESS_LEVEL = 6
COMPRESS_MIN_SIZE = 500
application = Flask(__name__)
Compress(application)
CORS(application)
application.config.from_object(os.environ['APP_SETTINGS'])
application.register_blueprint(data_controller)
application.json_encoder = CustomJSONEncoder
'''
error handling
'''
@application.errorhandler(400)
@application.errorhandler(401)
@application.errorhandler(403)
@application.errorhandler(404)
@application.errorhandler(405)
@application.errorhandler(406)
@application.errorhandler(408)
@application.errorhandler(409)
@application.errorhandler(410)
@application.errorhandler(423)
@application.errorhandler(500)
def error_handling_json(error):
print(error.description)
response = jsonify({'message': error.description})
return response, error.code
if __name__ == "__main__":
application.run()