-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapplication.py
More file actions
54 lines (36 loc) · 1.47 KB
/
application.py
File metadata and controls
54 lines (36 loc) · 1.47 KB
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
47
48
49
50
51
52
53
54
from flask import Flask, jsonify, Blueprint
from flask_jwt_extended import JWTManager
from flask_cors import CORS
from config import AppConfig, app_config
def create_app(config_=None):
app = Flask(__name__)
CORS(app)
app.config.from_object(app_config.get(config_) if config_ else AppConfig)
jwt = JWTManager(app)
@app.errorhandler(500)
def internal_server_error(e):
msg = "Sorry,we are experiencing some technical difficulties"
msg2 = "Please report this to cedriclusiba@gmail.com and check back with us soon"
return jsonify({'error': msg, "hint": msg2}), 500
@app.errorhandler(404)
def url_unknown(e):
msg = "Sorry, resource you are looking for does not exist"
return jsonify({"error": msg}), 404
@app.errorhandler(405)
def method_not_allowed(e):
msg = "Sorry, this action is not supported for this url"
return jsonify({'error': msg}), 405
@app.errorhandler(403)
def forbidden_resource(e):
msg = "Sorry, resource you are trying to access is forbidden"
return jsonify({'error': msg}), 403
@app.errorhandler(410)
def deleted_resource(e):
return jsonify({'error': "Sorry, this resource was deleted"}), 410
# register blueprints
from app.controllers import api, auth, questions, answers
app.register_blueprint(api)
app.register_blueprint(auth)
app.register_blueprint(answers)
app.register_blueprint(questions)
return app