Skip to content

Commit 30ae0d6

Browse files
authored
Implemented custom exceptions (#317)
# Purpose Implemented a custom list of exceptions to catch our own exceptions and handle them appropriately in specific manners depending on the type. Task: https://www.notion.so/uworbital/Create-custom-exceptions-1918a26d7677803dab4ce576a11a5ebb?pvs=4 # New Changes Created a custom list of exceptions that all inherit from a BaseOrbitalException class # Testing N/A # Outstanding Changes N/A
1 parent f02d89d commit 30ae0d6

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed

gs/backend/exceptions/__init__.py

Whitespace-only changes.
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
class BaseOrbitalError(Exception):
2+
"""
3+
@brief Base class for all orbital-related exceptions
4+
@attribute message (str) - Custom error message providing additional context
5+
"""
6+
7+
def __init__(self, message: str) -> None:
8+
super().__init__(message)
9+
self.message = message
10+
11+
12+
class ServiceError(BaseOrbitalError):
13+
"""
14+
@brief Exception related to general service errors
15+
@attribute message (str) - Service exception message
16+
"""
17+
18+
def __init__(self, message: str = "Service exception") -> None:
19+
super().__init__(message)
20+
21+
22+
class NotFoundError(ServiceError):
23+
"""
24+
@brief Exception raised when an item is not found
25+
@attribute message (str) - Item not found message
26+
"""
27+
28+
def __init__(self, message: str = "Item not found") -> None:
29+
super().__init__(message)
30+
31+
32+
class InvalidArgumentError(BaseOrbitalError):
33+
"""
34+
@brief Exception raised when an invalid argument is provided
35+
@attribute message (str) - Invalid argument message
36+
"""
37+
38+
def __init__(self, message: str = "The argument provided was invalid") -> None:
39+
super().__init__(message)
40+
41+
42+
class InvalidStateError(BaseOrbitalError):
43+
"""
44+
@brief Exception raised when an operation is performed in an invalid state
45+
@attribute message (str) - Invalid state message
46+
"""
47+
48+
def __init__(self, message: str = "Invalid state") -> None:
49+
super().__init__(message)
50+
51+
52+
class DatabaseError(BaseOrbitalError):
53+
"""
54+
@brief Exception raised for database-related errors
55+
@attribute message (str) - Database error message
56+
"""
57+
58+
def __init__(self, message: str = "There was a database error") -> None:
59+
super().__init__(message)
60+
61+
62+
class UnauthorizedError(BaseOrbitalError):
63+
"""
64+
@brief Exception raised when a user is not authorized to perform an action
65+
@attribute message (str) - Unauthorized error message
66+
"""
67+
68+
def __init__(self, message: str = "The current user is not authorized to perform this action") -> None:
69+
super().__init__(message)
70+
71+
72+
class UnknownError(BaseOrbitalError):
73+
"""
74+
@brief Exception raised for unexpected errors
75+
@attribute message (str) - Unknown error message
76+
"""
77+
78+
def __init__(self, message: str = "An unexpected error occurred") -> None:
79+
super().__init__(message)
80+
81+
82+
class SunPositionError(BaseOrbitalError):
83+
"""
84+
@brief Exception raised when an error occurs in sun position data generation
85+
@attribute message (str) - Sun position error message
86+
"""
87+
88+
def __init__(self, message: str = "There was an error when trying to generate the sun position data") -> None:
89+
super().__init__(message)

0 commit comments

Comments
 (0)