refactor: Moved ingestion exceptions to ingestion module

Moved custom ingestion exceptions to ingestion module

Refactor COG-502
This commit is contained in:
Igor Ilic 2024-11-29 17:15:54 +01:00
parent 1b2bdd9b83
commit eb09e5ad89
11 changed files with 37 additions and 25 deletions

View file

@ -11,8 +11,6 @@ from .exceptions import (
EntityNotFoundError,
EntityAlreadyExistsError,
InvalidOperationError,
PermissionDeniedError,
IngestionError,
InvalidValueError,
InvalidAttributeError,
)

View file

@ -70,24 +70,6 @@ class InvalidOperationError(CogneeApiError):
super().__init__(message, name, status_code)
class PermissionDeniedError(CogneeApiError):
def __init__(
self,
message: str = "User does not have permission on documents.",
name: str = "PermissionDeniedError",
status_code=status.HTTP_403_FORBIDDEN,
):
super().__init__(message, name, status_code)
class IngestionError(CogneeApiError):
def __init__(
self,
message: str = "Type of data sent to classify not supported.",
name: str = "IngestionError",
status_code=status.HTTP_415_UNSUPPORTED_MEDIA_TYPE,
):
super().__init__(message, name, status_code)
class InvalidValueError(CogneeApiError):
def __init__(
self,

View file

@ -3,7 +3,7 @@ from typing import Union, BinaryIO
from .data_types import TextData, BinaryData
from tempfile import SpooledTemporaryFile
from cognee.exceptions import IngestionError
from cognee.modules.ingestion.exceptions import IngestionError
def classify(data: Union[str, BinaryIO], filename: str = None):

View file

@ -0,0 +1,9 @@
"""
Custom exceptions for the Cognee API.
This module defines a set of exceptions for handling various ingestion errors
"""
from .exceptions import (
IngestionError,
)

View file

@ -0,0 +1,11 @@
from cognee.exceptions import CogneeApiError
from fastapi import status
class IngestionError(CogneeApiError):
def __init__(
self,
message: str = "Type of data sent to classify not supported.",
name: str = "IngestionError",
status_code=status.HTTP_415_UNSUPPORTED_MEDIA_TYPE,
):
super().__init__(message, name, status_code)

View file

@ -7,4 +7,5 @@ This module defines a set of exceptions for handling various user errors
from .exceptions import (
GroupNotFoundError,
UserNotFoundError,
PermissionDeniedError,
)

View file

@ -24,3 +24,13 @@ class UserNotFoundError(CogneeApiError):
status_code=status.HTTP_404_NOT_FOUND,
):
super().__init__(message, name, status_code)
class PermissionDeniedError(CogneeApiError):
def __init__(
self,
message: str = "User does not have permission on documents.",
name: str = "PermissionDeniedError",
status_code=status.HTTP_403_FORBIDDEN,
):
super().__init__(message, name, status_code)

View file

@ -3,7 +3,7 @@ from uuid import UUID
from sqlalchemy import select
from sqlalchemy.orm import joinedload
from cognee.exceptions import PermissionDeniedError
from cognee.modules.users.exceptions import PermissionDeniedError
from cognee.infrastructure.databases.relational import get_relational_engine
from ...models.User import User

View file

@ -11,7 +11,8 @@ import aiofiles
import pandas as pd
from pydantic import BaseModel
from cognee.exceptions import IngestionError, EntityNotFoundError
from cognee.exceptions import EntityNotFoundError
from cognee.modules.ingestion.exceptions import IngestionError
from cognee.infrastructure.llm.prompts import read_query_prompt
from cognee.infrastructure.llm.get_llm_client import get_llm_client
from cognee.infrastructure.data.chunking.config import get_chunk_config

View file

@ -1,6 +1,6 @@
from typing import Union, BinaryIO
from cognee.exceptions import IngestionError
from cognee.modules.ingestion.exceptions import IngestionError
from cognee.modules.ingestion import save_data_to_file
def save_data_item_to_storage(data_item: Union[BinaryIO, str], dataset_name: str) -> str:

View file

@ -1,6 +1,6 @@
from typing import Union, BinaryIO, Any
from cognee.exceptions import IngestionError
from cognee.modules.ingestion.exceptions import IngestionError
from cognee.modules.ingestion import save_data_to_file
def save_data_item_with_metadata_to_storage(data_item: Union[BinaryIO, str, Any], dataset_name: str) -> str: