mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-02-17 18:21:46 -05:00
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:
File diff suppressed because it is too large
Load Diff
@@ -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
|
||||
|
||||
@@ -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)",
|
||||
)
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user