summaryrefslogtreecommitdiff
path: root/jimbrella/exceptions.py
blob: 8e7734b1802999e7198086e02f3064cf0807e71d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"""Defines a few application-specific exceptions for Pythonic code."""


class UmbrellaNotFoundError(Exception):
    """For when an umbrella with required id is not found in database."""

    def __init__(self, umbid):
        self.id = umbid
        self.message = f"Umbrella {id} not found."
        super().__init__(self.message)


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


class UmbrellaValueError(Exception):
    """For when an admin enters an invalid value when modifying the database."""

    def __init__(self, field: str):
        self.field = field
        self.message = f"Invalid field: {field}."
        super().__init__(self.message)


class TenantIdentityError(Exception):
    """For when a tenant attempts to return an umbrella that's borrowed by another tenant."""

    def __init__(self, expected, got):
        self.expected = expected
        self.got = got
        self.message = f"Umbrella is borrowed by {expected} and {got} cannot return it."
        super().__init__(self.message)


class UsernameTakenError(Exception):
    """For when a username to be registered with is already taken."""

    def __init__(self, username: str):
        self.username = username
        self.message = f"Username {username} is already taken."
        super().__init__(self.message)