Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.
Python agentagentic-aiagentic-frameworkagentic-workflowaiautomationclaudedeepseekgenaigptllmlow-codemcpnextjsno-codeopenaipythonskillsworkflow
Restructure the File errors in controller (#23801)
Yongtao Huangbf2f03f9116a
diff --git a/api/controllers/common/errors.py b/api/controllers/common/errors.pyindex 9f762b3135e..6e2ea952fca 100644--- a/api/controllers/common/errors.py+++ b/api/controllers/common/errors.py@@ -1,5 +1,7 @@from werkzeug.exceptions import HTTPException+from libs.exception import BaseHTTPException+class FilenameNotExistsError(HTTPException):code = 400@@ -9,3 +11,27 @@ class FilenameNotExistsError(HTTPException):class RemoteFileUploadError(HTTPException):code = 400description = "Error uploading remote file."+++class FileTooLargeError(BaseHTTPException):+ error_code = "file_too_large"+ description = "File size exceeded. {message}"+ code = 413+++class UnsupportedFileTypeError(BaseHTTPException):+ error_code = "unsupported_file_type"+ description = "File type not allowed."+ code = 415+++class TooManyFilesError(BaseHTTPException):+ error_code = "too_many_files"+ description = "Only one file is allowed."+ code = 400+++class NoFileUploadedError(BaseHTTPException):+ error_code = "no_file_uploaded"+ description = "Please upload your file."+ code = 400diff --git a/api/controllers/console/app/annotation.py b/api/controllers/console/app/annotation.pyindex ee6011cd651..493a9a52e27 100644--- a/api/controllers/console/app/annotation.py+++ b/api/controllers/console/app/annotation.py@@ -3,9 +3,8 @@ from flask_login import current_userfrom flask_restful import Resource, marshal, marshal_with, reqparsefrom werkzeug.exceptions import Forbidden+from controllers.common.errors import NoFileUploadedError, TooManyFilesErrorfrom controllers.console import api-from controllers.console.app.error import NoFileUploadedError-from controllers.console.datasets.error import TooManyFilesErrorfrom controllers.console.wraps import (account_initialization_required,cloud_edition_billing_resource_check,diff --git a/api/controllers/console/app/error.py b/api/controllers/console/app/error.pyindex 1559f82d6ea..fbd7901646d 100644--- a/api/controllers/console/app/error.py+++ b/api/controllers/console/app/error.py@@ -79,18 +79,6 @@ class ProviderNotSupportSpeechToTextError(BaseHTTPException):code = 400-class NoFileUploadedError(BaseHTTPException):- error_code = "no_file_uploaded"- description = "Please upload your file."- code = 400---class TooManyFilesError(BaseHTTPException):- error_code = "too_many_files"- description = "Only one file is allowed."- code = 400--class DraftWorkflowNotExist(BaseHTTPException):error_code = "draft_workflow_not_exist"description = "Draft workflow need to be initialized."diff --git a/api/controllers/console/datasets/error.py b/api/controllers/console/datasets/error.pyindex cb68bb5e812..a43843b551d 100644--- a/api/controllers/console/datasets/error.py+++ b/api/controllers/console/datasets/error.py@@ -1,30 +1,6 @@from libs.exception import BaseHTTPException-class NoFileUploadedError(BaseHTTPException):- error_code = "no_file_uploaded"- description = "Please upload your file."- code = 400---class TooManyFilesError(BaseHTTPException):- error_code = "too_many_files"- description = "Only one file is allowed."- code = 400---class FileTooLargeError(BaseHTTPException):- error_code = "file_too_large"- description = "File size exceeded. {message}"- code = 413---class UnsupportedFileTypeError(BaseHTTPException):- error_code = "unsupported_file_type"- description = "File type not allowed."- code = 415--class DatasetNotInitializedError(BaseHTTPException):error_code = "dataset_not_initialized"description = "The dataset is still being initialized or indexing. Please wait a moment."diff --git a/api/controllers/console/error.py b/api/controllers/console/error.pyindex 0a4dfe1c102..0645d63be5f 100644--- a/api/controllers/console/error.py+++ b/api/controllers/console/error.py@@ -76,30 +76,6 @@ class EmailSendIpLimitError(BaseHTTPException):code = 429-class FileTooLargeError(BaseHTTPException):- error_code = "file_too_large"- description = "File size exceeded. {message}"- code = 413---class UnsupportedFileTypeError(BaseHTTPException):- error_code = "unsupported_file_type"- description = "File type not allowed."- code = 415---class TooManyFilesError(BaseHTTPException):- error_code = "too_many_files"- description = "Only one file is allowed."- code = 400---class NoFileUploadedError(BaseHTTPException):- error_code = "no_file_uploaded"- description = "Please upload your file."- code = 400--class UnauthorizedAndForceLogout(BaseHTTPException):error_code = "unauthorized_and_force_logout"description = "Unauthorized and force logout."diff --git a/api/controllers/console/files.py b/api/controllers/console/files.pyindex 256ff24b3b3..a87d270e9c9 100644--- a/api/controllers/console/files.py+++ b/api/controllers/console/files.py@@ -8,7 +8,13 @@ from werkzeug.exceptions import Forbiddenimport servicesfrom configs import dify_configfrom constants import DOCUMENT_EXTENSIONS-from controllers.common.errors import FilenameNotExistsError+from controllers.common.errors import (+ FilenameNotExistsError,+ FileTooLargeError,+ NoFileUploadedError,+ TooManyFilesError,+ UnsupportedFileTypeError,+)from controllers.console.wraps import (account_initialization_required,cloud_edition_billing_resource_check,@@ -18,13 +24,6 @@ from fields.file_fields import file_fields, upload_config_fieldsfrom libs.login import login_requiredfrom services.file_service import FileService-from .error import (- FileTooLargeError,- NoFileUploadedError,- TooManyFilesError,- UnsupportedFileTypeError,-)-PREVIEW_WORDS_LIMIT = 3000diff --git a/api/controllers/console/remote_files.py b/api/controllers/console/remote_files.pyindex b8cf019e4f0..c356113c402 100644--- a/api/controllers/console/remote_files.py+++ b/api/controllers/console/remote_files.py@@ -7,18 +7,17 @@ from flask_restful import Resource, marshal_with, reqparseimport servicesfrom controllers.common import helpers-from controllers.common.errors import RemoteFileUploadError+from controllers.common.errors import (+ FileTooLargeError,+ RemoteFileUploadError,+ UnsupportedFileTypeError,+)from core.file import helpers as file_helpersfrom core.helper import ssrf_proxyfrom fields.file_fields import file_fields_with_signed_url, remote_file_info_fieldsfrom models.account import Accountfrom services.file_service import FileService-from .error import (- FileTooLargeError,- UnsupportedFileTypeError,-)-class RemoteFileInfoApi(Resource):@marshal_with(remote_file_info_fields)diff --git a/api/controllers/console/workspace/workspace.py b/api/controllers/console/workspace/workspace.pyindex 6012c9ecc8a..f4f0078da7d 100644--- a/api/controllers/console/workspace/workspace.py+++ b/api/controllers/console/workspace/workspace.py@@ -7,15 +7,15 @@ from sqlalchemy import selectfrom werkzeug.exceptions import Unauthorizedimport services-from controllers.common.errors import FilenameNotExistsError-from controllers.console import api-from controllers.console.admin import admin_required-from controllers.console.datasets.error import (+from controllers.common.errors import (+ FilenameNotExistsError,FileTooLargeError,NoFileUploadedError,TooManyFilesError,UnsupportedFileTypeError,)+from controllers.console import api+from controllers.console.admin import admin_requiredfrom controllers.console.error import AccountNotLinkTenantErrorfrom controllers.console.wraps import (account_initialization_required,diff --git a/api/controllers/files/error.py b/api/controllers/files/error.pydeleted file mode 100644index a7ce4cd6f79..00000000000--- a/api/controllers/files/error.py+++ /dev/null@@ -1,7 +0,0 @@-from libs.exception import BaseHTTPException---class UnsupportedFileTypeError(BaseHTTPException):- error_code = "unsupported_file_type"- description = "File type not allowed."- code = 415diff --git a/api/controllers/files/image_preview.py b/api/controllers/files/image_preview.pyindex 46c19e1fbb3..91f7b27d1dd 100644--- a/api/controllers/files/image_preview.py+++ b/api/controllers/files/image_preview.py@@ -5,8 +5,8 @@ from flask_restful import Resource, reqparsefrom werkzeug.exceptions import NotFoundimport services+from controllers.common.errors import UnsupportedFileTypeErrorfrom controllers.files import api-from controllers.files.error import UnsupportedFileTypeErrorfrom services.account_service import TenantServicefrom services.file_service import FileServicediff --git a/api/controllers/files/tool_files.py b/api/controllers/files/tool_files.pyindex 1c3430ef4fd..d9c4e505118 100644--- a/api/controllers/files/tool_files.py+++ b/api/controllers/files/tool_files.py@@ -4,8 +4,8 @@ from flask import Responsefrom flask_restful import Resource, reqparsefrom werkzeug.exceptions import Forbidden, NotFound+from controllers.common.errors import UnsupportedFileTypeErrorfrom controllers.files import api-from controllers.files.error import UnsupportedFileTypeErrorfrom core.tools.signature import verify_tool_file_signaturefrom core.tools.tool_file_manager import ToolFileManagerfrom models import db as global_dbdiff --git a/api/controllers/files/upload.py b/api/controllers/files/upload.pyindex 15f93d2774a..bcc72d131c7 100644--- a/api/controllers/files/upload.py+++ b/api/controllers/files/upload.py@@ -5,11 +5,13 @@ from flask_restful import Resource, marshal_withfrom werkzeug.exceptions import Forbiddenimport services+from controllers.common.errors import (+ FileTooLargeError,+ UnsupportedFileTypeError,+)from controllers.console.wraps import setup_requiredfrom controllers.files import api-from controllers.files.error import UnsupportedFileTypeErrorfrom controllers.inner_api.plugin.wraps import get_user-from controllers.service_api.app.error import FileTooLargeErrorfrom core.file.helpers import verify_plugin_file_signaturefrom core.tools.tool_file_manager import ToolFileManagerfrom fields.file_fields import file_fieldsdiff --git a/api/controllers/service_api/app/error.py b/api/controllers/service_api/app/error.pyindex ba705f71e27..0e04a04cb24 100644--- a/api/controllers/service_api/app/error.py+++ b/api/controllers/service_api/app/error.py@@ -85,30 +85,6 @@ class ProviderNotSupportSpeechToTextError(BaseHTTPException):code = 400-class NoFileUploadedError(BaseHTTPException):- error_code = "no_file_uploaded"- description = "Please upload your file."- code = 400---class TooManyFilesError(BaseHTTPException):- error_code = "too_many_files"- description = "Only one file is allowed."- code = 400---class FileTooLargeError(BaseHTTPException):- error_code = "file_too_large"- description = "File size exceeded. {message}"- code = 413---class UnsupportedFileTypeError(BaseHTTPException):- error_code = "unsupported_file_type"- description = "File type not allowed."- code = 415--class FileNotFoundError(BaseHTTPException):error_code = "file_not_found"description = "The requested file was not found."diff --git a/api/controllers/service_api/app/file.py b/api/controllers/service_api/app/file.pyindex f09d07bcb6b..37153ca5dbf 100644--- a/api/controllers/service_api/app/file.py+++ b/api/controllers/service_api/app/file.py@@ -2,14 +2,14 @@ from flask import requestfrom flask_restful import Resource, marshal_withimport services-from controllers.common.errors import FilenameNotExistsError-from controllers.service_api import api-from controllers.service_api.app.error import (+from controllers.common.errors import (+ FilenameNotExistsError,FileTooLargeError,NoFileUploadedError,TooManyFilesError,UnsupportedFileTypeError,)+from controllers.service_api import apifrom controllers.service_api.wraps import FetchUserArg, WhereisUserArg, validate_app_tokenfrom fields.file_fields import file_fieldsfrom models.model import App, EndUserdiff --git a/api/controllers/service_api/dataset/document.py b/api/controllers/service_api/dataset/document.pyindex 2955d5d20d4..d0354f7851a 100644--- a/api/controllers/service_api/dataset/document.py+++ b/api/controllers/service_api/dataset/document.py@@ -6,15 +6,15 @@ from sqlalchemy import desc, selectfrom werkzeug.exceptions import Forbidden, NotFoundimport services-from controllers.common.errors import FilenameNotExistsError-from controllers.service_api import api-from controllers.service_api.app.error import (+from controllers.common.errors import (+ FilenameNotExistsError,FileTooLargeError,NoFileUploadedError,- ProviderNotInitializeError,TooManyFilesError,UnsupportedFileTypeError,)+from controllers.service_api import api+from controllers.service_api.app.error import ProviderNotInitializeErrorfrom controllers.service_api.dataset.error import (ArchivedDocumentImmutableError,DocumentIndexingError,diff --git a/api/controllers/service_api/dataset/error.py b/api/controllers/service_api/dataset/error.pyindex ecc47b40a12..e4214a16ad9 100644--- a/api/controllers/service_api/dataset/error.py+++ b/api/controllers/service_api/dataset/error.py@@ -1,30 +1,6 @@from libs.exception import BaseHTTPException-class NoFileUploadedError(BaseHTTPException):- error_code = "no_file_uploaded"- description = "Please upload your file."- code = 400---class TooManyFilesError(BaseHTTPException):- error_code = "too_many_files"- description = "Only one file is allowed."- code = 400---class FileTooLargeError(BaseHTTPException):- error_code = "file_too_large"- description = "File size exceeded. {message}"- code = 413---class UnsupportedFileTypeError(BaseHTTPException):- error_code = "unsupported_file_type"- description = "File type not allowed."- code = 415--class DatasetNotInitializedError(BaseHTTPException):error_code = "dataset_not_initialized"description = "The dataset is still being initialized or indexing. Please wait a moment."diff --git a/api/controllers/web/error.py b/api/controllers/web/error.pyindex 036e11d5c55..196a27e348b 100644--- a/api/controllers/web/error.py+++ b/api/controllers/web/error.py@@ -97,30 +97,6 @@ class ProviderNotSupportSpeechToTextError(BaseHTTPException):code = 400-class NoFileUploadedError(BaseHTTPException):- error_code = "no_file_uploaded"- description = "Please upload your file."- code = 400---class TooManyFilesError(BaseHTTPException):- error_code = "too_many_files"- description = "Only one file is allowed."- code = 400---class FileTooLargeError(BaseHTTPException):- error_code = "file_too_large"- description = "File size exceeded. {message}"- code = 413---class UnsupportedFileTypeError(BaseHTTPException):- error_code = "unsupported_file_type"- description = "File type not allowed."- code = 415--class WebAppAuthRequiredError(BaseHTTPException):error_code = "web_sso_auth_required"description = "Web app authentication required."diff --git a/api/controllers/web/files.py b/api/controllers/web/files.pyindex 8e9317606e4..0c304358250 100644--- a/api/controllers/web/files.py+++ b/api/controllers/web/files.py@@ -2,8 +2,13 @@ from flask import requestfrom flask_restful import marshal_withimport services-from controllers.common.errors import FilenameNotExistsError-from controllers.web.error import FileTooLargeError, NoFileUploadedError, TooManyFilesError, UnsupportedFileTypeError+from controllers.common.errors import (+ FilenameNotExistsError,+ FileTooLargeError,+ NoFileUploadedError,+ TooManyFilesError,+ UnsupportedFileTypeError,+)from controllers.web.wraps import WebApiResourcefrom fields.file_fields import file_fieldsfrom services.file_service import FileServicediff --git a/api/controllers/web/remote_files.py b/api/controllers/web/remote_files.pyindex ae68df6bdc4..4e19716c3df 100644--- a/api/controllers/web/remote_files.py+++ b/api/controllers/web/remote_files.py@@ -5,15 +5,17 @@ from flask_restful import marshal_with, reqparseimport servicesfrom controllers.common import helpers-from controllers.common.errors import RemoteFileUploadError+from controllers.common.errors import (+ FileTooLargeError,+ RemoteFileUploadError,+ UnsupportedFileTypeError,+)from controllers.web.wraps import WebApiResourcefrom core.file import helpers as file_helpersfrom core.helper import ssrf_proxyfrom fields.file_fields import file_fields_with_signed_url, remote_file_info_fieldsfrom services.file_service import FileService-from .error import FileTooLargeError, UnsupportedFileTypeError-class RemoteFileInfoApi(WebApiResource):@marshal_with(remote_file_info_fields)diff --git a/api/tests/unit_tests/controllers/console/test_files_security.py b/api/tests/unit_tests/controllers/console/test_files_security.pyindex cb5562d3451..2630fbcfd0c 100644--- a/api/tests/unit_tests/controllers/console/test_files_security.py+++ b/api/tests/unit_tests/controllers/console/test_files_security.py@@ -4,8 +4,8 @@ from unittest.mock import patchimport pytestfrom werkzeug.exceptions import Forbidden-from controllers.common.errors import FilenameNotExistsError-from controllers.console.error import (+from controllers.common.errors import (+ FilenameNotExistsError,FileTooLargeError,NoFileUploadedError,TooManyFilesError,