Introduce gen_api_error for all API requests

master
Felix Stupp 11 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,
)
from entertainment_decider.extras import (
gen_api_error,
remove_common_trails,
)
@ -755,9 +756,7 @@ def refresh_collections() -> ResponseReturnValue:
"title": coll.title,
"uri": coll.primary_uri,
},
"error": {
"args": repr(e.args),
},
"error": gen_api_error(e),
},
)
update_element_lookup_cache(changed_colls)
@ -937,10 +936,7 @@ def api_collection_extract_mass() -> ResponseReturnValue:
errors.append(
{
"uri": u,
"error": {
"type": repr(type(e)),
"args": repr(e.args),
},
"error": gen_api_error(e),
}
)
if errors:
@ -1121,10 +1117,7 @@ def api_media_extract_mass() -> ResponseReturnValue:
errors.append(
{
"uri": u,
"error": {
"type": repr(type(e)),
"args": repr(e.args),
},
"error": gen_api_error(e),
}
)
if errors:

@ -1,4 +1,5 @@
from .chain import Chain
from .errors import gen_api_error
from .strings import remove_common_trails
from .typing import LazyValue
@ -6,5 +7,6 @@ from .typing import LazyValue
__all__ = [
"Chain",
"LazyValue",
"gen_api_error",
"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