init
This commit is contained in:
0
utils/__init__.py
Normal file
0
utils/__init__.py
Normal file
11
utils/error_handler.py
Normal file
11
utils/error_handler.py
Normal 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
18
utils/json_encoder.py
Normal 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)
|
Reference in New Issue
Block a user