Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ed0e0d1

Browse files
Sid MohanSid Mohan
Sid Mohan
authored and
Sid Mohan
committedAug 18, 2024
exceptions.py
1 parent a8681fc commit ed0e0d1

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
 

‎datafog/exceptions.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# exceptions.py
2+
3+
class DataFogException(Exception):
4+
"""Base exception for DataFog SDK"""
5+
def __init__(self, message: str, status_code: int = None):
6+
self.message = message
7+
self.status_code = status_code
8+
super().__init__(self.message)
9+
10+
class BadRequestError(DataFogException):
11+
"""Exception raised for 400 Bad Request errors"""
12+
def __init__(self, message: str):
13+
super().__init__(message, status_code=400)
14+
15+
class UnprocessableEntityError(DataFogException):
16+
"""Exception raised for 422 Unprocessable Entity errors"""
17+
def __init__(self, message: str):
18+
super().__init__(message, status_code=422)
19+
20+
def raise_for_status_code(status_code: int, error_message: str):
21+
"""Raise the appropriate exception based on the status code"""
22+
if status_code == 400:
23+
raise BadRequestError(error_message)
24+
elif status_code == 422:
25+
raise UnprocessableEntityError(error_message)

0 commit comments

Comments
 (0)
Failed to load comments.