summaryrefslogtreecommitdiff
path: root/jimbrella/database.py
diff options
context:
space:
mode:
authorFrederick Yin <fkfd@fkfd.me>2021-10-22 10:28:01 +0800
committerFrederick Yin <fkfd@fkfd.me>2021-10-22 10:28:01 +0800
commita3d400705e53b131997dc5e9c6ac10f2b5502761 (patch)
treeeb072599b76c947024f1218b88f3366782a79087 /jimbrella/database.py
parent2697f216b707ae83bcdaa5688fdb91d1f662d61d (diff)
Define application-specific exceptions
Diffstat (limited to 'jimbrella/database.py')
-rw-r--r--jimbrella/database.py9
1 files changed, 5 insertions, 4 deletions
diff --git a/jimbrella/database.py b/jimbrella/database.py
index 014b5b5..63cba49 100644
--- a/jimbrella/database.py
+++ b/jimbrella/database.py
@@ -3,6 +3,7 @@ import os
from datetime import datetime, timedelta
from .utils import human_datetime, human_timedelta
from .config import DUE_HOURS
+from .exceptions import *
class Database:
@@ -201,9 +202,9 @@ class Database:
"""When a user has borrowed an umbrella."""
umb = self._find_by_serial(serial)
if umb is None:
- raise ValueError(f"No umbrella with serial {serial} found.")
+ raise UmbrellaNotFoundError
elif umb["status"] != "available":
- raise ValueError(f"Umbrella with serial {serial} is inavailable.")
+ raise UmbrellaStatusError
umb["status"] = "lent"
umb["tenant_name"] = tenant_name
umb["tenant_id"] = tenant_id
@@ -216,9 +217,9 @@ class Database:
"""When a user has returned an umbrella."""
umb = self._find_by_serial(serial)
if umb is None:
- raise ValueError(f"No umbrella with serial {serial} found.")
+ raise UmbrellaNotFoundError
elif umb["status"] not in ("lent", "overdue"):
- raise ValueError(f"Umbrella with serial {serial} is not lent out.")
+ raise UmbrellaStatusError
umb["status"] = "available"
for key in ["tenant_name", "tenant_id", "tenant_phone", "tenant_email"]:
umb[key] = ""