summaryrefslogtreecommitdiff
path: root/jimbrella
diff options
context:
space:
mode:
Diffstat (limited to 'jimbrella')
-rw-r--r--jimbrella/database.py9
-rw-r--r--jimbrella/exceptions.py11
2 files changed, 16 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] = ""
diff --git a/jimbrella/exceptions.py b/jimbrella/exceptions.py
new file mode 100644
index 0000000..3b7fa4c
--- /dev/null
+++ b/jimbrella/exceptions.py
@@ -0,0 +1,11 @@
+"""Defines a few application-specific exceptions for Pythonic code."""
+class UmbrellaNotFoundError(Exception):
+ """For when an umbrella with required serial is not found in database."""
+ pass
+
+
+class UmbrellaStatusError(Exception):
+ """For when the umbrella to be lent is not available, or when an umbrella to be returned has
+ never been taken away. Most likely duplicate or erroneous answer sheets submitted by user.
+ """
+ pass