-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sid Mohan
authored and
Sid Mohan
committed
Aug 18, 2024
1 parent
a8681fc
commit ed0e0d1
Showing
1 changed file
with
25 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# exceptions.py | ||
|
||
class DataFogException(Exception): | ||
"""Base exception for DataFog SDK""" | ||
def __init__(self, message: str, status_code: int = None): | ||
self.message = message | ||
self.status_code = status_code | ||
super().__init__(self.message) | ||
|
||
class BadRequestError(DataFogException): | ||
"""Exception raised for 400 Bad Request errors""" | ||
def __init__(self, message: str): | ||
super().__init__(message, status_code=400) | ||
|
||
class UnprocessableEntityError(DataFogException): | ||
"""Exception raised for 422 Unprocessable Entity errors""" | ||
def __init__(self, message: str): | ||
super().__init__(message, status_code=422) | ||
|
||
def raise_for_status_code(status_code: int, error_message: str): | ||
"""Raise the appropriate exception based on the status code""" | ||
if status_code == 400: | ||
raise BadRequestError(error_message) | ||
elif status_code == 422: | ||
raise UnprocessableEntityError(error_message) |