Skip to content

armgit / dify

Public Imported from GitHub
0

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.

fix: replace str(e) with generic messages in error responses (#43049)

Juhyuk choid2fe62a9fd7d
diff --git a/api/controllers/console/datasets/external.py b/api/controllers/console/datasets/external.py
index 3f86a1c61f7..4324ad16597 100644
--- a/api/controllers/console/datasets/external.py
+++ b/api/controllers/console/datasets/external.py
@@ -1,5 +1,6 @@
from __future__ import annotations
+import logging
from datetime import datetime
from typing import Any, Never
from uuid import UUID
@@ -36,6 +37,7 @@ from services.errors.dataset import DatasetNameDuplicateError as DatasetNameDupl
from services.knowledge.dataset_access import DatasetAccessDeniedError, DatasetNotFoundError
from services.knowledge.external.application import ExternalHitTestingError, ExternalTemplateNotFoundError
+logger = logging.getLogger(__name__)
_DATASET_EDIT_ROLES = frozenset(
{TenantAccountRole.OWNER, TenantAccountRole.ADMIN, TenantAccountRole.EDITOR, TenantAccountRole.DATASET_OPERATOR}
)
@@ -50,7 +52,8 @@ def _raise_external_error(error: Exception) -> Never:
if isinstance(error, DatasetNameDuplicateFailure):
raise DatasetNameDuplicateError() from error
if isinstance(error, ExternalHitTestingError):
- raise InternalServerError(str(error)) from error
+ logger.exception("External hit testing failed")
+ raise InternalServerError() from error
raise error
diff --git a/api/controllers/console/datasets/hit_testing_base.py b/api/controllers/console/datasets/hit_testing_base.py
index a1a59cbd401..893d0d7b08f 100644
--- a/api/controllers/console/datasets/hit_testing_base.py
+++ b/api/controllers/console/datasets/hit_testing_base.py
@@ -157,6 +157,6 @@ class DatasetsHitTestingBase:
raise CompletionRequestError(e.description)
except ValueError as e:
raise ValueError(str(e))
- except Exception as e:
+ except Exception:
logger.exception("Hit testing failed.")
- raise InternalServerError(str(e))
+ raise InternalServerError()
diff --git a/api/tests/unit_tests/controllers/console/datasets/test_hit_testing_base.py b/api/tests/unit_tests/controllers/console/datasets/test_hit_testing_base.py
index 68a0944ada7..b3d9a6a1ec4 100644
--- a/api/tests/unit_tests/controllers/console/datasets/test_hit_testing_base.py
+++ b/api/tests/unit_tests/controllers/console/datasets/test_hit_testing_base.py
@@ -291,5 +291,6 @@ class TestPerformHitTesting:
"retrieve",
side_effect=Exception("boom"),
):
- with pytest.raises(InternalServerError, match="boom"):
+ with pytest.raises(InternalServerError) as exc_info:
DatasetsHitTestingBase.perform_hit_testing(Mock(), dataset, {"query": "hello"}, account, "tenant-1")
+ assert "boom" not in str(exc_info.value)