Skip to content

Commit

Permalink
pre-commit
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 ed0e0d1 commit 1154527
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion datafog/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
# 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)
raise UnprocessableEntityError(error_message)

0 comments on commit 1154527

Please sign in to comment.