feat: api error handling restruct
This commit is contained in:
parent
32996aa0d0
commit
bed523a36b
5 changed files with 46 additions and 61 deletions
|
|
@ -129,9 +129,7 @@ class config:
|
|||
if hasattr(relational_db_config, key):
|
||||
object.__setattr__(relational_db_config, key, value)
|
||||
else:
|
||||
raise InvalidAttributeError(
|
||||
message=f"'{key}' is not a valid attribute of the config."
|
||||
)
|
||||
raise InvalidConfigAttributeError(attribute=key)
|
||||
|
||||
@staticmethod
|
||||
def set_migration_db_config(config_dict: dict):
|
||||
|
|
@ -143,9 +141,7 @@ class config:
|
|||
if hasattr(migration_db_config, key):
|
||||
object.__setattr__(migration_db_config, key, value)
|
||||
else:
|
||||
raise InvalidAttributeError(
|
||||
message=f"'{key}' is not a valid attribute of the config."
|
||||
)
|
||||
raise InvalidConfigAttributeError(attribute=key)
|
||||
|
||||
@staticmethod
|
||||
def set_graph_db_config(config_dict: dict) -> None:
|
||||
|
|
@ -169,9 +165,7 @@ class config:
|
|||
if hasattr(vector_db_config, key):
|
||||
object.__setattr__(vector_db_config, key, value)
|
||||
else:
|
||||
raise InvalidAttributeError(
|
||||
message=f"'{key}' is not a valid attribute of the config."
|
||||
)
|
||||
InvalidConfigAttributeError(attribute=key)
|
||||
|
||||
@staticmethod
|
||||
def set_vector_db_key(db_key: str):
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ from cognee.modules.users.methods import get_default_user
|
|||
from cognee.modules.data.methods import get_authorized_existing_datasets
|
||||
from cognee.context_global_variables import set_database_global_context_variables
|
||||
|
||||
from cognee.api.v1.delete.exceptions import (
|
||||
from cognee.api.v1.exceptions import (
|
||||
DocumentNotFoundError,
|
||||
DatasetNotFoundError,
|
||||
DocumentSubgraphNotFoundError,
|
||||
|
|
|
|||
|
|
@ -1,50 +0,0 @@
|
|||
from cognee.exceptions import CogneeApiError
|
||||
from fastapi import status
|
||||
|
||||
|
||||
class DocumentNotFoundError(CogneeApiError):
|
||||
"""Raised when a document cannot be found in the database."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
message: str = "Document not found in database.",
|
||||
name: str = "DocumentNotFoundError",
|
||||
status_code: int = status.HTTP_404_NOT_FOUND,
|
||||
):
|
||||
super().__init__(message, name, status_code)
|
||||
|
||||
|
||||
class DatasetNotFoundError(CogneeApiError):
|
||||
"""Raised when a dataset cannot be found."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
message: str = "Dataset not found.",
|
||||
name: str = "DatasetNotFoundError",
|
||||
status_code: int = status.HTTP_404_NOT_FOUND,
|
||||
):
|
||||
super().__init__(message, name, status_code)
|
||||
|
||||
|
||||
class DataNotFoundError(CogneeApiError):
|
||||
"""Raised when a dataset cannot be found."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
message: str = "Data not found.",
|
||||
name: str = "DataNotFoundError",
|
||||
status_code: int = status.HTTP_404_NOT_FOUND,
|
||||
):
|
||||
super().__init__(message, name, status_code)
|
||||
|
||||
|
||||
class DocumentSubgraphNotFoundError(CogneeApiError):
|
||||
"""Raised when a document's subgraph cannot be found in the graph database."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
message: str = "Document subgraph not found in graph database.",
|
||||
name: str = "DocumentSubgraphNotFoundError",
|
||||
status_code: int = status.HTTP_404_NOT_FOUND,
|
||||
):
|
||||
super().__init__(message, name, status_code)
|
||||
|
|
@ -5,5 +5,9 @@ This module defines a set of exceptions for handling various data errors
|
|||
"""
|
||||
|
||||
from .exceptions import (
|
||||
InvalidConfigAttributeError
|
||||
InvalidConfigAttributeError,
|
||||
DocumentNotFoundError,
|
||||
DatasetNotFoundError,
|
||||
DataNotFoundError,
|
||||
DocumentSubgraphNotFoundError
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
from cognee.exceptions import (
|
||||
CogneeConfigurationError,
|
||||
CogneeValidationError
|
||||
)
|
||||
from fastapi import status
|
||||
|
||||
|
|
@ -13,3 +14,39 @@ class InvalidConfigAttributeError(CogneeConfigurationError):
|
|||
):
|
||||
message = f"'{attribute}' is not a valid attribute of the configuration."
|
||||
super().__init__(message, name, status_code)
|
||||
|
||||
class DocumentNotFoundError(CogneeValidationError):
|
||||
def __init__(
|
||||
self,
|
||||
message: str = "Document not found in database.",
|
||||
name: str = "DocumentNotFoundError",
|
||||
status_code: int = status.HTTP_404_NOT_FOUND,
|
||||
):
|
||||
super().__init__(message, name, status_code)
|
||||
|
||||
class DatasetNotFoundError(CogneeValidationError):
|
||||
def __init__(
|
||||
self,
|
||||
message: str = "Dataset not found.",
|
||||
name: str = "DatasetNotFoundError",
|
||||
status_code: int = status.HTTP_404_NOT_FOUND,
|
||||
):
|
||||
super().__init__(message, name, status_code)
|
||||
|
||||
class DataNotFoundError(CogneeValidationError):
|
||||
def __init__(
|
||||
self,
|
||||
message: str = "Data not found.",
|
||||
name: str = "DataNotFoundError",
|
||||
status_code: int = status.HTTP_404_NOT_FOUND,
|
||||
):
|
||||
super().__init__(message, name, status_code)
|
||||
|
||||
class DocumentSubgraphNotFoundError(CogneeValidationError):
|
||||
def __init__(
|
||||
self,
|
||||
message: str = "Document subgraph not found in graph database.",
|
||||
name: str = "DocumentSubgraphNotFoundError",
|
||||
status_code: int = status.HTTP_404_NOT_FOUND,
|
||||
):
|
||||
super().__init__(message, name, status_code)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue