refactor: Move exceptions into a separate file

This commit is contained in:
Vikash Kothary 2022-10-14 23:36:13 +01:00
parent e94bb778c0
commit 97a740417b
2 changed files with 7 additions and 3 deletions

View File

@ -0,0 +1 @@
from webob.exc import HTTPBadRequest as BadRequestException

View File

@ -1,10 +1,11 @@
import shutil import shutil
from sqlite3 import dbapi2 as sqlite from sqlite3 import dbapi2 as sqlite
from webob.exc import HTTPBadRequest
from anki.db import DB from anki.db import DB
from anki.collection import Collection from anki.collection import Collection
from ankisyncd.exceptions import BadRequestException
class FullSyncManager: class FullSyncManager:
def test_db(self, db: DB): def test_db(self, db: DB):
@ -12,7 +13,7 @@ class FullSyncManager:
:param anki.db.DB db: the database uploaded from the client. :param anki.db.DB db: the database uploaded from the client.
""" """
if db.scalar("pragma integrity_check") != "ok": if db.scalar("pragma integrity_check") != "ok":
raise HTTPBadRequest( raise BadRequestException(
"Integrity check failed for uploaded collection database file." "Integrity check failed for uploaded collection database file."
) )
@ -34,7 +35,9 @@ class FullSyncManager:
with DB(temp_db_path) as test_db: with DB(temp_db_path) as test_db:
self.test_db(test_db) self.test_db(test_db)
except sqlite.Error as e: except sqlite.Error as e:
raise HTTPBadRequest("Uploaded collection database file is " "corrupt.") raise BadRequestException(
"Uploaded collection database file is " "corrupt."
)
# Overwrite existing db. # Overwrite existing db.
col.close() col.close()