From e49789ede127e51498b3ca651303f9a6fad46102 Mon Sep 17 00:00:00 2001 From: Felix Stupp Date: Sun, 6 Aug 2023 13:02:09 +0200 Subject: [PATCH] force_refresh_collection: Implement better API error handling --- server/app.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/server/app.py b/server/app.py index aa66173..fdd7a4b 100644 --- a/server/app.py +++ b/server/app.py @@ -803,7 +803,25 @@ def force_refresh_collection(collection_id: int) -> ResponseReturnValue: coll: MediaCollection = MediaCollection.get(id=collection_id) if coll is None: return "404 Not Found", 404 - state = collection_update(coll, check_cache_expired=False) + try: + state = collection_update(coll, check_cache_expired=False) + except Exception as e: + orm.rollback() + return ( + { + "status": False, + "error": { + "msg": "Failed to update collection successfully", + "data": [ + { + "collection": coll.json_summary, + "error": gen_api_error(e), + } + ], + }, + }, + 501, + ) if state.may_has_changed: update_element_lookup_cache((coll.id,)) return redirect_back_or_okay()