From 97a740417b238e85907320944119bde21a36eaae Mon Sep 17 00:00:00 2001 From: Vikash Kothary Date: Fri, 14 Oct 2022 23:36:13 +0100 Subject: [PATCH] refactor: Move exceptions into a separate file --- src/ankisyncd/exceptions.py | 1 + src/ankisyncd/full_sync/manager.py | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 src/ankisyncd/exceptions.py diff --git a/src/ankisyncd/exceptions.py b/src/ankisyncd/exceptions.py new file mode 100644 index 0000000..2de99f7 --- /dev/null +++ b/src/ankisyncd/exceptions.py @@ -0,0 +1 @@ +from webob.exc import HTTPBadRequest as BadRequestException diff --git a/src/ankisyncd/full_sync/manager.py b/src/ankisyncd/full_sync/manager.py index 7add8c1..bd5e66e 100644 --- a/src/ankisyncd/full_sync/manager.py +++ b/src/ankisyncd/full_sync/manager.py @@ -1,10 +1,11 @@ import shutil from sqlite3 import dbapi2 as sqlite -from webob.exc import HTTPBadRequest from anki.db import DB from anki.collection import Collection +from ankisyncd.exceptions import BadRequestException + class FullSyncManager: def test_db(self, db: DB): @@ -12,7 +13,7 @@ class FullSyncManager: :param anki.db.DB db: the database uploaded from the client. """ if db.scalar("pragma integrity_check") != "ok": - raise HTTPBadRequest( + raise BadRequestException( "Integrity check failed for uploaded collection database file." ) @@ -34,7 +35,9 @@ class FullSyncManager: with DB(temp_db_path) as test_db: self.test_db(test_db) except sqlite.Error as e: - raise HTTPBadRequest("Uploaded collection database file is " "corrupt.") + raise BadRequestException( + "Uploaded collection database file is " "corrupt." + ) # Overwrite existing db. col.close()