Introduce gen_api_error for all API requests

master
Felix Stupp 12 months ago
parent 0d9a3a54e1
commit a3dd645cb7
Signed by: zocker
GPG Key ID: 93E1BD26F6B02FB7

@ -69,6 +69,7 @@ from entertainment_decider.extractors.media import (
media_update, media_update,
) )
from entertainment_decider.extras import ( from entertainment_decider.extras import (
gen_api_error,
remove_common_trails, remove_common_trails,
) )
@ -755,9 +756,7 @@ def refresh_collections() -> ResponseReturnValue:
"title": coll.title, "title": coll.title,
"uri": coll.primary_uri, "uri": coll.primary_uri,
}, },
"error": { "error": gen_api_error(e),
"args": repr(e.args),
},
}, },
) )
update_element_lookup_cache(changed_colls) update_element_lookup_cache(changed_colls)
@ -937,10 +936,7 @@ def api_collection_extract_mass() -> ResponseReturnValue:
errors.append( errors.append(
{ {
"uri": u, "uri": u,
"error": { "error": gen_api_error(e),
"type": repr(type(e)),
"args": repr(e.args),
},
} }
) )
if errors: if errors:
@ -1121,10 +1117,7 @@ def api_media_extract_mass() -> ResponseReturnValue:
errors.append( errors.append(
{ {
"uri": u, "uri": u,
"error": { "error": gen_api_error(e),
"type": repr(type(e)),
"args": repr(e.args),
},
} }
) )
if errors: if errors:

@ -1,4 +1,5 @@
from .chain import Chain from .chain import Chain
from .errors import gen_api_error
from .strings import remove_common_trails from .strings import remove_common_trails
from .typing import LazyValue from .typing import LazyValue
@ -6,5 +7,6 @@ from .typing import LazyValue
__all__ = [ __all__ = [
"Chain", "Chain",
"LazyValue", "LazyValue",
"gen_api_error",
"remove_common_trails", "remove_common_trails",
] ]

@ -0,0 +1,12 @@
from __future__ import annotations
from traceback import format_exception
from typing import Dict
def gen_api_error(exc: Exception) -> Dict:
return {
"type": repr(type(exc)),
"args": repr(exc.args),
"traceback": list(format_exception(exc)),
}
Loading…
Cancel
Save