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 (
|
from .exceptions import (
|
||||||
CogneeApiError,
|
CogneeApiError,
|
||||||
ServiceError,
|
CogneeSystemError,
|
||||||
InvalidValueError,
|
CogneeValidationError,
|
||||||
InvalidAttributeError,
|
CogneeConfigurationError,
|
||||||
CriticalError,
|
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -35,37 +35,50 @@ class CogneeApiError(Exception):
|
||||||
return f"{self.name}: {self.message} (Status code: {self.status_code})"
|
return f"{self.name}: {self.message} (Status code: {self.status_code})"
|
||||||
|
|
||||||
|
|
||||||
class ServiceError(CogneeApiError):
|
class CogneeSystemError(CogneeApiError):
|
||||||
"""Failures in external services or APIs, like a database or a third-party service"""
|
"""System error"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
message: str = "Service is unavailable.",
|
message: str = "A system error occurred.",
|
||||||
name: str = "ServiceError",
|
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,
|
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
||||||
):
|
):
|
||||||
super().__init__(message, name, status_code)
|
super().__init__(message, name, status_code)
|
||||||
|
|
||||||
|
|
||||||
class InvalidValueError(CogneeApiError):
|
class CogneeConfigurationError(CogneeApiError):
|
||||||
|
"""SystemConfigError"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
message: str = "Invalid Value.",
|
message: str = "A system configuration error occurred.",
|
||||||
name: str = "InvalidValueError",
|
name: str = "CogneeConfigurationError",
|
||||||
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||||
):
|
):
|
||||||
super().__init__(message, name, status_code)
|
super().__init__(message, name, status_code)
|
||||||
|
|
||||||
|
|
||||||
class InvalidAttributeError(CogneeApiError):
|
class CogneeTransientError(CogneeApiError):
|
||||||
|
"""TransientError"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
message: str = "Invalid attribute.",
|
message: str = "A transient error occurred.",
|
||||||
name: str = "InvalidAttributeError",
|
name: str = "CogneeTransientError",
|
||||||
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
|
||||||
):
|
):
|
||||||
super().__init__(message, name, status_code)
|
super().__init__(message, name, status_code)
|
||||||
|
|
||||||
|
|
||||||
class CriticalError(CogneeApiError):
|
|
||||||
pass
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue