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 10:51:07 +08:00
parent b5e90e77aa
commit 1b32e70dc5
3 changed files with 19 additions and 5 deletions

View File

@ -46,6 +46,8 @@ class PipelineTemplateDetailApi(Resource):
type = request.args.get("type", default="built-in", type=str)
rag_pipeline_service = RagPipelineService()
pipeline_template = rag_pipeline_service.get_pipeline_template_detail(template_id, type)
if not pipeline_template:
return {"error": "Pipeline template not found from upstream service."}, 404
return pipeline_template, 200

View File

@ -35,17 +35,21 @@ class RemotePipelineTemplateRetrieval(PipelineTemplateRetrievalBase):
return PipelineTemplateType.REMOTE
@classmethod
def fetch_pipeline_template_detail_from_dify_official(cls, template_id: str) -> dict | None:
def fetch_pipeline_template_detail_from_dify_official(cls, template_id: str) -> dict:
"""
Fetch pipeline template detail from dify official.
:param template_id: Pipeline ID
:return:
:param template_id: Pipeline template ID
:return: Template detail dict
:raises ValueError: When upstream returns a non-200 status code
"""
domain = dify_config.HOSTED_FETCH_PIPELINE_TEMPLATES_REMOTE_DOMAIN
url = f"{domain}/pipeline-templates/{template_id}"
response = httpx.get(url, timeout=httpx.Timeout(10.0, connect=3.0))
if response.status_code != 200:
return None
raise ValueError(
f"fetch pipeline template detail failed, status_code: {response.status_code}, response: {response.text}"
)
data: dict = response.json()
return data

View File

@ -117,13 +117,21 @@ class RagPipelineService:
def get_pipeline_template_detail(cls, template_id: str, type: str = "built-in") -> dict | None:
"""
Get pipeline template detail.
:param template_id: template id
:return:
:param type: template type, "built-in" or "customized"
:return: template detail dict, or None if not found
"""
if type == "built-in":
mode = dify_config.HOSTED_FETCH_PIPELINE_TEMPLATES_MODE
retrieval_instance = PipelineTemplateRetrievalFactory.get_pipeline_template_factory(mode)()
built_in_result: dict | None = retrieval_instance.get_pipeline_template_detail(template_id)
if not built_in_result:
logger.warning(
"pipeline template not found after all retrieval attempts, template_id: %s, mode: %s",
template_id,
mode,
)
return built_in_result
else:
mode = "customized"