-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
60 lines (47 loc) · 1.21 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import json
from flasgger import Swagger
from flask import Flask, jsonify, redirect
from werkzeug.exceptions import HTTPException
from config import Config
from mini_redis_api import RedisAPI
config = Config()
app = Flask(__name__)
swagger = Swagger(app)
app.register_blueprint(RedisAPI.blueprint, url_prefix="/mini-redis")
@app.errorhandler(HTTPException)
def handle_http_exception(e):
"""
Handles HTTP exceptions
"""
response = e.get_response()
response.data = json.dumps(
{
"code": e.code,
"name": e.name,
"description": e.description,
}
)
response.content_type = "application/json"
return response
@app.errorhandler(Exception)
def handle_exception(e):
"""
Handles non-HTTP exceptions
"""
response = jsonify(
{
"code": 500,
"name": "Internal Server Error",
"description": str(e),
}
)
response.status_code = 500
return response
@app.route("/")
def redirect_to_apidocs():
"""
Redirects all base requests to the API docs endpoint
"""
return redirect("/apidocs")
if __name__ == "__main__":
app.run(port=config.get_port(), debug=config.get_debug())