mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-19 19:09:08 +08:00
fix: unify error handling
This commit is contained in:
parent
772009115d
commit
8c5928da2f
@ -38,7 +38,7 @@ from core.indexing_runner import IndexingRunner
|
||||
from core.model_manager import ModelManager
|
||||
from core.model_runtime.entities.model_entities import ModelType
|
||||
from core.model_runtime.errors.invoke import InvokeAuthorizationError
|
||||
from core.plugin.manager.exc import PluginNotFoundError
|
||||
from core.plugin.manager.exc import PluginDaemonClientSideError
|
||||
from core.rag.extractor.entity.extract_setting import ExtractSetting
|
||||
from extensions.ext_database import db
|
||||
from extensions.ext_redis import redis_client
|
||||
@ -416,7 +416,7 @@ class DocumentIndexingEstimateApi(DocumentResource):
|
||||
)
|
||||
except ProviderTokenNotInitError as ex:
|
||||
raise ProviderNotInitializeError(ex.description)
|
||||
except PluginNotFoundError as ex:
|
||||
except PluginDaemonClientSideError as ex:
|
||||
raise ProviderNotInitializeError(ex.description)
|
||||
except Exception as e:
|
||||
raise IndexingEstimateError(str(e))
|
||||
@ -519,7 +519,7 @@ class DocumentBatchIndexingEstimateApi(DocumentResource):
|
||||
)
|
||||
except ProviderTokenNotInitError as ex:
|
||||
raise ProviderNotInitializeError(ex.description)
|
||||
except PluginNotFoundError as ex:
|
||||
except PluginDaemonClientSideError as ex:
|
||||
raise ProviderNotInitializeError(ex.description)
|
||||
except Exception as e:
|
||||
raise IndexingEstimateError(str(e))
|
||||
|
@ -10,7 +10,7 @@ from controllers.console import api
|
||||
from controllers.console.workspace import plugin_permission_required
|
||||
from controllers.console.wraps import account_initialization_required, setup_required
|
||||
from core.model_runtime.utils.encoders import jsonable_encoder
|
||||
from core.plugin.manager.exc import PluginDaemonBadRequestError
|
||||
from core.plugin.manager.exc import PluginDaemonClientSideError
|
||||
from libs.login import login_required
|
||||
from models.account import TenantPluginPermission
|
||||
from services.plugin.plugin_permission_service import PluginPermissionService
|
||||
@ -31,7 +31,7 @@ class PluginDebuggingKeyApi(Resource):
|
||||
"host": dify_config.PLUGIN_REMOTE_INSTALL_HOST,
|
||||
"port": dify_config.PLUGIN_REMOTE_INSTALL_PORT,
|
||||
}
|
||||
except PluginDaemonBadRequestError as e:
|
||||
except PluginDaemonClientSideError as e:
|
||||
raise ValueError(e)
|
||||
|
||||
|
||||
@ -43,7 +43,7 @@ class PluginListApi(Resource):
|
||||
tenant_id = current_user.current_tenant_id
|
||||
try:
|
||||
plugins = PluginService.list(tenant_id)
|
||||
except PluginDaemonBadRequestError as e:
|
||||
except PluginDaemonClientSideError as e:
|
||||
raise ValueError(e)
|
||||
|
||||
return jsonable_encoder({"plugins": plugins})
|
||||
@ -62,7 +62,7 @@ class PluginListInstallationsFromIdsApi(Resource):
|
||||
|
||||
try:
|
||||
plugins = PluginService.list_installations_from_ids(tenant_id, args["plugin_ids"])
|
||||
except PluginDaemonBadRequestError as e:
|
||||
except PluginDaemonClientSideError as e:
|
||||
raise ValueError(e)
|
||||
|
||||
return jsonable_encoder({"plugins": plugins})
|
||||
@ -78,7 +78,7 @@ class PluginIconApi(Resource):
|
||||
|
||||
try:
|
||||
icon_bytes, mimetype = PluginService.get_asset(args["tenant_id"], args["filename"])
|
||||
except PluginDaemonBadRequestError as e:
|
||||
except PluginDaemonClientSideError as e:
|
||||
raise ValueError(e)
|
||||
|
||||
icon_cache_max_age = dify_config.TOOL_ICON_CACHE_MAX_AGE
|
||||
@ -102,7 +102,7 @@ class PluginUploadFromPkgApi(Resource):
|
||||
content = file.read()
|
||||
try:
|
||||
response = PluginService.upload_pkg(tenant_id, content)
|
||||
except PluginDaemonBadRequestError as e:
|
||||
except PluginDaemonClientSideError as e:
|
||||
raise ValueError(e)
|
||||
|
||||
return jsonable_encoder(response)
|
||||
@ -124,7 +124,7 @@ class PluginUploadFromGithubApi(Resource):
|
||||
|
||||
try:
|
||||
response = PluginService.upload_pkg_from_github(tenant_id, args["repo"], args["version"], args["package"])
|
||||
except PluginDaemonBadRequestError as e:
|
||||
except PluginDaemonClientSideError as e:
|
||||
raise ValueError(e)
|
||||
|
||||
return jsonable_encoder(response)
|
||||
@ -147,7 +147,7 @@ class PluginUploadFromBundleApi(Resource):
|
||||
content = file.read()
|
||||
try:
|
||||
response = PluginService.upload_bundle(tenant_id, content)
|
||||
except PluginDaemonBadRequestError as e:
|
||||
except PluginDaemonClientSideError as e:
|
||||
raise ValueError(e)
|
||||
|
||||
return jsonable_encoder(response)
|
||||
@ -172,7 +172,7 @@ class PluginInstallFromPkgApi(Resource):
|
||||
|
||||
try:
|
||||
response = PluginService.install_from_local_pkg(tenant_id, args["plugin_unique_identifiers"])
|
||||
except PluginDaemonBadRequestError as e:
|
||||
except PluginDaemonClientSideError as e:
|
||||
raise ValueError(e)
|
||||
|
||||
return jsonable_encoder(response)
|
||||
@ -201,7 +201,7 @@ class PluginInstallFromGithubApi(Resource):
|
||||
args["version"],
|
||||
args["package"],
|
||||
)
|
||||
except PluginDaemonBadRequestError as e:
|
||||
except PluginDaemonClientSideError as e:
|
||||
raise ValueError(e)
|
||||
|
||||
return jsonable_encoder(response)
|
||||
@ -226,7 +226,7 @@ class PluginInstallFromMarketplaceApi(Resource):
|
||||
|
||||
try:
|
||||
response = PluginService.install_from_marketplace_pkg(tenant_id, args["plugin_unique_identifiers"])
|
||||
except PluginDaemonBadRequestError as e:
|
||||
except PluginDaemonClientSideError as e:
|
||||
raise ValueError(e)
|
||||
|
||||
return jsonable_encoder(response)
|
||||
@ -252,7 +252,7 @@ class PluginFetchManifestApi(Resource):
|
||||
).model_dump()
|
||||
}
|
||||
)
|
||||
except PluginDaemonBadRequestError as e:
|
||||
except PluginDaemonClientSideError as e:
|
||||
raise ValueError(e)
|
||||
|
||||
|
||||
@ -273,7 +273,7 @@ class PluginFetchInstallTasksApi(Resource):
|
||||
return jsonable_encoder(
|
||||
{"tasks": PluginService.fetch_install_tasks(tenant_id, args["page"], args["page_size"])}
|
||||
)
|
||||
except PluginDaemonBadRequestError as e:
|
||||
except PluginDaemonClientSideError as e:
|
||||
raise ValueError(e)
|
||||
|
||||
|
||||
@ -287,7 +287,7 @@ class PluginFetchInstallTaskApi(Resource):
|
||||
|
||||
try:
|
||||
return jsonable_encoder({"task": PluginService.fetch_install_task(tenant_id, task_id)})
|
||||
except PluginDaemonBadRequestError as e:
|
||||
except PluginDaemonClientSideError as e:
|
||||
raise ValueError(e)
|
||||
|
||||
|
||||
@ -301,7 +301,7 @@ class PluginDeleteInstallTaskApi(Resource):
|
||||
|
||||
try:
|
||||
return {"success": PluginService.delete_install_task(tenant_id, task_id)}
|
||||
except PluginDaemonBadRequestError as e:
|
||||
except PluginDaemonClientSideError as e:
|
||||
raise ValueError(e)
|
||||
|
||||
|
||||
@ -315,7 +315,7 @@ class PluginDeleteAllInstallTaskItemsApi(Resource):
|
||||
|
||||
try:
|
||||
return {"success": PluginService.delete_all_install_task_items(tenant_id)}
|
||||
except PluginDaemonBadRequestError as e:
|
||||
except PluginDaemonClientSideError as e:
|
||||
raise ValueError(e)
|
||||
|
||||
|
||||
@ -329,7 +329,7 @@ class PluginDeleteInstallTaskItemApi(Resource):
|
||||
|
||||
try:
|
||||
return {"success": PluginService.delete_install_task_item(tenant_id, task_id, identifier)}
|
||||
except PluginDaemonBadRequestError as e:
|
||||
except PluginDaemonClientSideError as e:
|
||||
raise ValueError(e)
|
||||
|
||||
|
||||
@ -352,7 +352,7 @@ class PluginUpgradeFromMarketplaceApi(Resource):
|
||||
tenant_id, args["original_plugin_unique_identifier"], args["new_plugin_unique_identifier"]
|
||||
)
|
||||
)
|
||||
except PluginDaemonBadRequestError as e:
|
||||
except PluginDaemonClientSideError as e:
|
||||
raise ValueError(e)
|
||||
|
||||
|
||||
@ -383,7 +383,7 @@ class PluginUpgradeFromGithubApi(Resource):
|
||||
args["package"],
|
||||
)
|
||||
)
|
||||
except PluginDaemonBadRequestError as e:
|
||||
except PluginDaemonClientSideError as e:
|
||||
raise ValueError(e)
|
||||
|
||||
|
||||
@ -401,7 +401,7 @@ class PluginUninstallApi(Resource):
|
||||
|
||||
try:
|
||||
return {"success": PluginService.uninstall(tenant_id, args["plugin_installation_id"])}
|
||||
except PluginDaemonBadRequestError as e:
|
||||
except PluginDaemonClientSideError as e:
|
||||
raise ValueError(e)
|
||||
|
||||
|
||||
|
@ -9,33 +9,41 @@ class PluginDaemonError(Exception):
|
||||
return f"{self.__class__.__name__}: {self.description}"
|
||||
|
||||
|
||||
class PluginDaemonInternalServerError(PluginDaemonError):
|
||||
class PluginDaemonInternalError(PluginDaemonError):
|
||||
pass
|
||||
|
||||
|
||||
class PluginDaemonClientSideError(PluginDaemonError):
|
||||
pass
|
||||
|
||||
|
||||
class PluginDaemonInternalServerError(PluginDaemonInternalError):
|
||||
description: str = "Internal Server Error"
|
||||
|
||||
|
||||
class PluginDaemonBadRequestError(PluginDaemonError):
|
||||
description: str = "Bad Request"
|
||||
|
||||
|
||||
class PluginDaemonNotFoundError(PluginDaemonError):
|
||||
description: str = "Not Found"
|
||||
|
||||
|
||||
class PluginInvokeError(PluginDaemonError):
|
||||
description: str = "Invoke Error"
|
||||
|
||||
|
||||
class PluginUniqueIdentifierError(PluginDaemonError):
|
||||
description: str = "Unique Identifier Error"
|
||||
|
||||
|
||||
class PluginNotFoundError(PluginDaemonError):
|
||||
description: str = "Plugin Not Found"
|
||||
|
||||
|
||||
class PluginDaemonUnauthorizedError(PluginDaemonError):
|
||||
class PluginDaemonUnauthorizedError(PluginDaemonInternalError):
|
||||
description: str = "Unauthorized"
|
||||
|
||||
|
||||
class PluginPermissionDeniedError(PluginDaemonError):
|
||||
class PluginDaemonNotFoundError(PluginDaemonInternalError):
|
||||
description: str = "Not Found"
|
||||
|
||||
|
||||
class PluginDaemonBadRequestError(PluginDaemonClientSideError):
|
||||
description: str = "Bad Request"
|
||||
|
||||
|
||||
class PluginInvokeError(PluginDaemonClientSideError):
|
||||
description: str = "Invoke Error"
|
||||
|
||||
|
||||
class PluginUniqueIdentifierError(PluginDaemonClientSideError):
|
||||
description: str = "Unique Identifier Error"
|
||||
|
||||
|
||||
class PluginNotFoundError(PluginDaemonClientSideError):
|
||||
description: str = "Plugin Not Found"
|
||||
|
||||
|
||||
class PluginPermissionDeniedError(PluginDaemonClientSideError):
|
||||
description: str = "Permission Denied"
|
||||
|
@ -7,7 +7,7 @@ from sqlalchemy.orm import Session
|
||||
|
||||
from core.callback_handler.workflow_tool_callback_handler import DifyWorkflowCallbackHandler
|
||||
from core.file import File, FileTransferMethod, FileType
|
||||
from core.plugin.manager.exc import PluginInvokeError
|
||||
from core.plugin.manager.exc import PluginDaemonClientSideError
|
||||
from core.tools.entities.tool_entities import ToolInvokeMessage, ToolParameter
|
||||
from core.tools.tool_engine import ToolEngine
|
||||
from core.tools.tool_manager import ToolManager
|
||||
@ -105,7 +105,7 @@ class ToolNode(BaseNode[ToolNodeData]):
|
||||
try:
|
||||
# convert tool messages
|
||||
yield from self._transform_message(message_stream, tool_info, parameters_for_log)
|
||||
except PluginInvokeError as e:
|
||||
except PluginDaemonClientSideError as e:
|
||||
yield RunCompletedEvent(
|
||||
run_result=NodeRunResult(
|
||||
status=WorkflowNodeExecutionStatus.FAILED,
|
||||
|
@ -6,7 +6,7 @@ from configs import dify_config
|
||||
from core.helper.position_helper import is_filtered
|
||||
from core.model_runtime.utils.encoders import jsonable_encoder
|
||||
from core.plugin.entities.plugin import GenericProviderID
|
||||
from core.plugin.manager.exc import PluginInvokeError
|
||||
from core.plugin.manager.exc import PluginDaemonClientSideError
|
||||
from core.tools.builtin_tool.providers._positions import BuiltinToolProviderSort
|
||||
from core.tools.entities.api_entities import ToolApiEntity, ToolProviderApiEntity
|
||||
from core.tools.errors import ToolNotFoundError, ToolProviderCredentialValidationError, ToolProviderNotFoundError
|
||||
@ -139,7 +139,7 @@ class BuiltinToolManageService:
|
||||
# encrypt credentials
|
||||
credentials = tool_configuration.encrypt(credentials)
|
||||
except (
|
||||
PluginInvokeError,
|
||||
PluginDaemonClientSideError,
|
||||
ToolProviderNotFoundError,
|
||||
ToolNotFoundError,
|
||||
ToolProviderCredentialValidationError,
|
||||
|
Loading…
x
Reference in New Issue
Block a user