Encode datetime in JSON as ISO string
This commit is contained in:
parent
bd657d11b6
commit
0edd55b64e
|
@ -4,6 +4,8 @@
|
||||||
Initialize also a singleton for the AccessTokenController and start the Thread.
|
Initialize also a singleton for the AccessTokenController and start the Thread.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
import logging
|
import logging
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
|
@ -33,6 +35,8 @@ class CustomJSONEncoder(JSONEncoder):
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
if isinstance(o, datetime):
|
||||||
|
return o.isoformat()
|
||||||
# Check if iterable
|
# Check if iterable
|
||||||
try:
|
try:
|
||||||
iterable = iter(o)
|
iterable = iter(o)
|
||||||
|
@ -76,7 +80,7 @@ def create_app():
|
||||||
def handle_exception(e):
|
def handle_exception(e):
|
||||||
if isinstance(e, HTTPException):
|
if isinstance(e, HTTPException):
|
||||||
logger.debug(e.description, exc_info=True)
|
logger.debug(e.description, exc_info=True)
|
||||||
return jsonify({"error": e.name}), e.code
|
return jsonify({"error": e.description}), e.code
|
||||||
|
|
||||||
logger.error(str(e), exc_info=True)
|
logger.error(str(e), exc_info=True)
|
||||||
return jsonify({"error": "Internal server error occurred"}), 500
|
return jsonify({"error": "Internal server error occurred"}), 500
|
||||||
|
|
Loading…
Reference in New Issue