-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor exception handling: Define custom exceptions as subclasses o…
…f a base Errors class (#465) * Refactor exception handling: Define custom exceptions as subclasses of a base Errors class * Update errors.py * format code, fix and sort imports * remove unused error class imports across project --------- Co-authored-by: Daniel Fernau <[email protected]>
- Loading branch information
1 parent
226fdf4
commit 73b2d12
Showing
6 changed files
with
65 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,44 @@ | ||
class Errors: | ||
def __init__(self) -> None: | ||
pass | ||
|
||
class ProtectError(Exception): | ||
def __init__(self, code: int) -> None: | ||
self.code = code | ||
super().__init__(f"ProtectError with code: {code}") | ||
class Error(Exception): | ||
"""Base class for all custom exceptions in this project. | ||
This class can be used as a catch-all for project-specific exceptions, allowing | ||
for uniform handling or logging of errors unique to this application. | ||
""" | ||
|
||
pass | ||
|
||
|
||
class ProtectError(Error): | ||
"""Handles errors related to core application functionality. | ||
Attributes: | ||
code (int): Numeric identifier for the type of error encountered, useful for | ||
diagnostics or user feedback. | ||
""" | ||
|
||
def __init__(self, code: int): | ||
# Assign the error code for further reference | ||
self.code = code | ||
# Construct the base exception message with the specific error code | ||
super().__init__(f"ProtectError with error code: {code}") | ||
|
||
|
||
class DownloadFailed(Error): | ||
"""Signifies that a file download process has been unsuccessful. | ||
Raises when there are issues with downloading files, excluding authorization | ||
problems, which are handled by `AuthorizationFailed`. Common causes might include | ||
network failures or file access issues. | ||
""" | ||
|
||
pass | ||
|
||
|
||
class AuthorizationFailed(Error): | ||
"""Represents failures in the authorization or authentication process. | ||
This should be used when access is denied due to invalid credentials, expired sessions, | ||
or any other issues specifically related to gaining authorized access. | ||
""" | ||
|
||
pass |