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:
parent
7d1210c889
commit
df0b4b4820
5 changed files with 39 additions and 26 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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"""
|
||||
|
||||
|
|
|
|||
10
cognee/modules/users/exceptions/__init__.py
Normal file
10
cognee/modules/users/exceptions/__init__.py
Normal 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,
|
||||
)
|
||||
26
cognee/modules/users/exceptions/exceptions.py
Normal file
26
cognee/modules/users/exceptions/exceptions.py
Normal 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)
|
||||
Loading…
Add table
Reference in a new issue