feat: adds new Exception classes
This commit is contained in:
parent
fd9aaf57b1
commit
ed555a731d
2 changed files with 31 additions and 19 deletions
|
|
@ -7,8 +7,7 @@ such as service failures, resource conflicts, and invalid operations.
|
|||
|
||||
from .exceptions import (
|
||||
CogneeApiError,
|
||||
ServiceError,
|
||||
InvalidValueError,
|
||||
InvalidAttributeError,
|
||||
CriticalError,
|
||||
CogneeSystemError,
|
||||
CogneeValidationError,
|
||||
CogneeConfigurationError,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -35,37 +35,50 @@ class CogneeApiError(Exception):
|
|||
return f"{self.name}: {self.message} (Status code: {self.status_code})"
|
||||
|
||||
|
||||
class ServiceError(CogneeApiError):
|
||||
"""Failures in external services or APIs, like a database or a third-party service"""
|
||||
class CogneeSystemError(CogneeApiError):
|
||||
"""System error"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
message: str = "Service is unavailable.",
|
||||
name: str = "ServiceError",
|
||||
message: str = "A system error occurred.",
|
||||
name: str = "CogneeSystemError",
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
):
|
||||
super().__init__(message, name, status_code)
|
||||
|
||||
|
||||
class CogneeValidationError(CogneeApiError):
|
||||
"""Validation error"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
message: str = "A validation error occurred.",
|
||||
name: str = "CogneeValidationError",
|
||||
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
||||
):
|
||||
super().__init__(message, name, status_code)
|
||||
|
||||
|
||||
class InvalidValueError(CogneeApiError):
|
||||
class CogneeConfigurationError(CogneeApiError):
|
||||
"""SystemConfigError"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
message: str = "Invalid Value.",
|
||||
name: str = "InvalidValueError",
|
||||
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
||||
message: str = "A system configuration error occurred.",
|
||||
name: str = "CogneeConfigurationError",
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
):
|
||||
super().__init__(message, name, status_code)
|
||||
|
||||
|
||||
class InvalidAttributeError(CogneeApiError):
|
||||
class CogneeTransientError(CogneeApiError):
|
||||
"""TransientError"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
message: str = "Invalid attribute.",
|
||||
name: str = "InvalidAttributeError",
|
||||
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
||||
message: str = "A transient error occurred.",
|
||||
name: str = "CogneeTransientError",
|
||||
status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
|
||||
):
|
||||
super().__init__(message, name, status_code)
|
||||
|
||||
|
||||
class CriticalError(CogneeApiError):
|
||||
pass
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue