From ed555a731d2c904a5cf0c24240be565c973ffd88 Mon Sep 17 00:00:00 2001 From: hajdul88 <52442977+hajdul88@users.noreply.github.com> Date: Wed, 13 Aug 2025 11:27:45 +0200 Subject: [PATCH] feat: adds new Exception classes --- cognee/exceptions/__init__.py | 7 +++--- cognee/exceptions/exceptions.py | 43 +++++++++++++++++++++------------ 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/cognee/exceptions/__init__.py b/cognee/exceptions/__init__.py index d1d4ecbf5..496ad63c5 100644 --- a/cognee/exceptions/__init__.py +++ b/cognee/exceptions/__init__.py @@ -7,8 +7,7 @@ such as service failures, resource conflicts, and invalid operations. from .exceptions import ( CogneeApiError, - ServiceError, - InvalidValueError, - InvalidAttributeError, - CriticalError, + CogneeSystemError, + CogneeValidationError, + CogneeConfigurationError, ) diff --git a/cognee/exceptions/exceptions.py b/cognee/exceptions/exceptions.py index 46e0af1a8..e7eb784b8 100644 --- a/cognee/exceptions/exceptions.py +++ b/cognee/exceptions/exceptions.py @@ -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