-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
46 lines (36 loc) · 1.06 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
from decouple import config
from flask import jsonify
from config import create_app
from db import db
app = create_app(config('config.DevelopmentConfig'))
@app.teardown_request
def commit_transaction_on_teardown(exception=None):
if exception is None:
try:
db.session.commit()
except Exception as e:
db.session.rollback()
return (
jsonify(
{
"error": "An error occurred while saving data. Please try again later."
}
),
500,
)
else:
db.session.rollback() # rollback in case of any exception
return (
jsonify(
{
"error": "An unexpected error occurred. Please contact support if the issue persists."
}
),
500,
)
@app.teardown_appcontext
def shutdown_session(response, exception=None):
db.session.remove()
return response
if __name__ == "__main__":
app.run(debug=True)