mirror of
https://github.com/langgenius/dify.git
synced 2026-09-08 11:04:27 +08:00
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:
parent
2f0f97aa66
commit
b85af2ec47
@ -15,7 +15,8 @@ class RemotePipelineTemplateRetrieval(PipelineTemplateRetrievalBase):
|
|||||||
Retrieval recommended app from dify official
|
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:
|
try:
|
||||||
result = self.fetch_pipeline_template_detail_from_dify_official(template_id)
|
result = self.fetch_pipeline_template_detail_from_dify_official(template_id)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -48,7 +49,9 @@ class RemotePipelineTemplateRetrieval(PipelineTemplateRetrievalBase):
|
|||||||
response = httpx.get(url, timeout=httpx.Timeout(10.0, connect=3.0))
|
response = httpx.get(url, timeout=httpx.Timeout(10.0, connect=3.0))
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
raise ValueError(
|
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()
|
data: dict = response.json()
|
||||||
return data
|
return data
|
||||||
|
|||||||
@ -59,6 +59,44 @@ class TestPipelineTemplateDetailApi:
|
|||||||
assert status == 200
|
assert status == 200
|
||||||
assert response == template
|
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:
|
class TestCustomizedPipelineTemplateApi:
|
||||||
def test_patch_success(self, app):
|
def test_patch_success(self, app):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user