refactor: Move user and group errors to users module

Moved user and group errors to users module

Refactor #COG-502
This commit is contained in:
Igor Ilic 2024-11-29 17:06:34 +01:00
parent 7d1210c889
commit df0b4b4820
5 changed files with 39 additions and 26 deletions

View file

@ -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

View file

@ -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

View file

@ -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"""

View file

@ -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,
)

View file

@ -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)