Skip to content

Commit

Permalink
exceptions.py
Browse files Browse the repository at this point in the history
  • 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.
25 changes: 25 additions & 0 deletions datafog/exceptions.py
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)

0 comments on commit ed0e0d1

Please sign in to comment.