diff --git a/cognee/api/v1/permissions/routers/get_permissions_router.py b/cognee/api/v1/permissions/routers/get_permissions_router.py index 30491ec7d..8d012d600 100644 --- a/cognee/api/v1/permissions/routers/get_permissions_router.py +++ b/cognee/api/v1/permissions/routers/get_permissions_router.py @@ -2,7 +2,7 @@ from fastapi import APIRouter, Depends, HTTPException from fastapi.responses import JSONResponse from sqlalchemy.orm import Session -from cognee.exceptions import GroupNotFoundError, UserNotFoundError +from cognee.modules.users.exceptions import UserNotFoundError, GroupNotFoundError from cognee.modules.users import get_user_db from cognee.modules.users.models import User, Group, Permission diff --git a/cognee/api/v1/search/search_v2.py b/cognee/api/v1/search/search_v2.py index d18ba3b6e..d77aa5fa8 100644 --- a/cognee/api/v1/search/search_v2.py +++ b/cognee/api/v1/search/search_v2.py @@ -3,10 +3,11 @@ from uuid import UUID from enum import Enum from typing import Callable, Dict -from cognee.exceptions import UserNotFoundError, InvalidValueError +from cognee.exceptions import InvalidValueError from cognee.modules.search.operations import log_query, log_result from cognee.modules.storage.utils import JSONEncoder from cognee.shared.utils import send_telemetry +from cognee.modules.users.exceptions import UserNotFoundError from cognee.modules.users.models import User from cognee.modules.users.methods import get_default_user from cognee.modules.users.permissions.methods import get_document_ids_for_user diff --git a/cognee/exceptions/exceptions.py b/cognee/exceptions/exceptions.py index 752376f60..2ea9ded1e 100644 --- a/cognee/exceptions/exceptions.py +++ b/cognee/exceptions/exceptions.py @@ -34,30 +34,6 @@ class ServiceError(CogneeApiError): super().__init__(message, name, status_code) -class GroupNotFoundError(CogneeApiError): - """User group not found""" - - def __init__( - self, - message: str = "User group not found.", - name: str = "GroupNotFoundError", - status_code=status.HTTP_404_NOT_FOUND, - ): - super().__init__(message, name, status_code) - - -class UserNotFoundError(CogneeApiError): - """User not found""" - - def __init__( - self, - message: str = "No user found in the system. Please create a user.", - name: str = "UserNotFoundError", - status_code=status.HTTP_404_NOT_FOUND, - ): - super().__init__(message, name, status_code) - - class EntityNotFoundError(CogneeApiError): """Database returns nothing""" diff --git a/cognee/modules/users/exceptions/__init__.py b/cognee/modules/users/exceptions/__init__.py new file mode 100644 index 000000000..ee4f99eda --- /dev/null +++ b/cognee/modules/users/exceptions/__init__.py @@ -0,0 +1,10 @@ +""" +Custom exceptions for the Cognee API. + +This module defines a set of exceptions for handling various user errors +""" + +from .exceptions import ( + GroupNotFoundError, + UserNotFoundError, +) \ No newline at end of file diff --git a/cognee/modules/users/exceptions/exceptions.py b/cognee/modules/users/exceptions/exceptions.py new file mode 100644 index 000000000..d45531746 --- /dev/null +++ b/cognee/modules/users/exceptions/exceptions.py @@ -0,0 +1,26 @@ +from cognee.exceptions import CogneeApiError +from fastapi import status + + +class GroupNotFoundError(CogneeApiError): + """User group not found""" + + def __init__( + self, + message: str = "User group not found.", + name: str = "GroupNotFoundError", + status_code=status.HTTP_404_NOT_FOUND, + ): + super().__init__(message, name, status_code) + + +class UserNotFoundError(CogneeApiError): + """User not found""" + + def __init__( + self, + message: str = "No user found in the system. Please create a user.", + name: str = "UserNotFoundError", + status_code=status.HTTP_404_NOT_FOUND, + ): + super().__init__(message, name, status_code)