This commit is contained in:
Sense T
2022-08-08 05:51:01 +00:00
commit 135a9dd01d
16 changed files with 213 additions and 0 deletions

0
utils/__init__.py Normal file
View File

11
utils/error_handler.py Normal file
View File

@@ -0,0 +1,11 @@
import traceback
from app import app
def error_handler(e):
app.logger.warning(e, traceback.format_exc())
return {
'success': False,
'message': 'Error: {0}'.format(str(e)),
'data': None
}, 500

18
utils/json_encoder.py Normal file
View File

@@ -0,0 +1,18 @@
from flask.json import JSONEncoder
import datetime
import decimal
class JSONEncoder(JSONEncoder):
def default(self, obj):
try:
if isinstance(obj, datetime.datetime):
return obj.strftime('%Y-%m-%d %H:%M:%S')
elif isinstance(obj, decimal.Decimal):
return float(obj)
iterable = iter(obj)
except TypeError:
pass
else:
return list(iterable)
return JSONEncoder.default(self, obj)