From 2121510f63365e4a0f6089759cb95dd2e6ba11c8 Mon Sep 17 00:00:00 2001 From: Willem Jiang Date: Sat, 12 Jul 2025 23:31:43 +0800 Subject: [PATCH] fix:catch toolCalls doesn't return validate json (#405) Co-authored-by: Willem Jiang <143703838+willem-bd@users.noreply.github.com> --- web/src/components/deer-flow/link.tsx | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/web/src/components/deer-flow/link.tsx b/web/src/components/deer-flow/link.tsx index fcf1830..aca6b74 100644 --- a/web/src/components/deer-flow/link.tsx +++ b/web/src/components/deer-flow/link.tsx @@ -22,12 +22,20 @@ export const Link = ({ (toolCalls || []).forEach((call) => { if (call && call.name === "web_search" && call.result) { - const result = JSON.parse(call.result) as Array<{ url: string }>; - result.forEach((r) => { - // encodeURI is used to handle the case where the link contains chinese or other special characters - links.add(encodeURI(r.url)); - links.add(r.url); - }); + try { + const result = JSON.parse(call.result) as Array<{ url: string }>; + if (Array.isArray(result)) { + result.forEach((r) => { + if (r && typeof r.url === 'string') { + // encodeURI is used to handle the case where the link contains chinese or other special characters + links.add(encodeURI(r.url)); + links.add(r.url); + } + }); + } + } catch (error) { + console.warn('Failed to parse web_search result:', error); + } } }); return links;