feat(api): add FolderAlreadyExistsError exception handling

- Introduced `FolderAlreadyExistsError` to handle cases where a folder with the same name already exists, improving error management in folder operations.
- Updated the REST API to include this new exception in the error handling mechanism, providing clearer responses for folder-related requests.
- Refactored import statements for better organization and clarity in the codebase.
- Enhanced the `list_library_agents` and `list_favorite_library_agents` functions by simplifying the error handling logic and improving readability.
This commit is contained in:
abhi1992002
2026-02-17 12:03:53 +05:30
parent d60d79efb6
commit ee14e54e80
4 changed files with 659 additions and 795 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -2,3 +2,9 @@ class FolderValidationError(Exception):
"""Raised when folder operations fail validation."""
pass
class FolderAlreadyExistsError(FolderValidationError):
"""Raised when a folder with the same name already exists in the location."""
pass

View File

@@ -566,5 +566,5 @@ class LibraryAgentUpdateRequest(pydantic.BaseModel):
)
folder_id: Optional[str] = pydantic.Field(
default=None,
description="Folder ID to move agent to (empty string for root)",
description="Folder ID to move agent to (None to move to root)",
)

View File

@@ -45,7 +45,10 @@ from backend.api.features.chat.completion_consumer import (
start_completion_consumer,
stop_completion_consumer,
)
from backend.api.features.library.exceptions import FolderValidationError
from backend.api.features.library.exceptions import (
FolderAlreadyExistsError,
FolderValidationError,
)
from backend.blocks.llm import DEFAULT_LLM_MODEL
from backend.data.model import Credentials
from backend.integrations.providers import ProviderName
@@ -278,6 +281,7 @@ async def validation_error_handler(
app.add_exception_handler(PrismaError, handle_internal_http_error(500))
app.add_exception_handler(FolderAlreadyExistsError, handle_internal_http_error(409, False))
app.add_exception_handler(FolderValidationError, handle_internal_http_error(400, False))
app.add_exception_handler(NotFoundError, handle_internal_http_error(404, False))
app.add_exception_handler(NotAuthorizedError, handle_internal_http_error(403, False))