fix: When can not obtain pipeline template detail failed from upstream service including remote template service and database, return responding error message.

This commit is contained in:
FFXN
2026-03-18 11:20:50 +08:00
parent 2f0f97aa66
commit b85af2ec47
2 changed files with 43 additions and 2 deletions

View File

@ -15,7 +15,8 @@ class RemotePipelineTemplateRetrieval(PipelineTemplateRetrievalBase):
Retrieval recommended app from dify official
"""
def get_pipeline_template_detail(self, template_id: str):
def get_pipeline_template_detail(self, template_id: str) -> dict | None:
result: dict | None
try:
result = self.fetch_pipeline_template_detail_from_dify_official(template_id)
except Exception as e:
@ -48,7 +49,9 @@ class RemotePipelineTemplateRetrieval(PipelineTemplateRetrievalBase):
response = httpx.get(url, timeout=httpx.Timeout(10.0, connect=3.0))
if response.status_code != 200:
raise ValueError(
f"fetch pipeline template detail failed, status_code: {response.status_code}, response: {response.text[:1000]}"
f"fetch pipeline template detail failed,"
+ f" status_code: {response.status_code},"
+ f" response: {response.text[:1000]}"
)
data: dict = response.json()
return data

View File

@ -59,6 +59,44 @@ class TestPipelineTemplateDetailApi:
assert status == 200
assert response == template
def test_get_returns_404_when_template_not_found(self, app):
api = PipelineTemplateDetailApi()
method = unwrap(api.get)
service = MagicMock()
service.get_pipeline_template_detail.return_value = None
with (
app.test_request_context("/?type=built-in"),
patch(
"controllers.console.datasets.rag_pipeline.rag_pipeline.RagPipelineService",
return_value=service,
),
):
response, status = method(api, "non-existent-id")
assert status == 404
assert "error" in response
def test_get_returns_404_for_customized_type_not_found(self, app):
api = PipelineTemplateDetailApi()
method = unwrap(api.get)
service = MagicMock()
service.get_pipeline_template_detail.return_value = None
with (
app.test_request_context("/?type=customized"),
patch(
"controllers.console.datasets.rag_pipeline.rag_pipeline.RagPipelineService",
return_value=service,
),
):
response, status = method(api, "non-existent-id")
assert status == 404
assert "error" in response
class TestCustomizedPipelineTemplateApi:
def test_patch_success(self, app):