Encode datetime in JSON as ISO string

This commit is contained in:
Ferdinand Thiessen 2020-09-05 22:26:36 +02:00
parent bd657d11b6
commit 0edd55b64e
1 changed files with 5 additions and 1 deletions

View File

@ -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