From 7d38e5f900a31cc47384f573893b4f0b57c1ce8b Mon Sep 17 00:00:00 2001 From: Lan <913088741@qq.com> Date: Thu, 12 Jun 2025 20:43:50 +0800 Subject: [PATCH] feat: append try catch (#280) --- web/src/core/api/chat.ts | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/web/src/core/api/chat.ts b/web/src/core/api/chat.ts index 1706ba1..af5a2b5 100644 --- a/web/src/core/api/chat.ts +++ b/web/src/core/api/chat.ts @@ -40,21 +40,26 @@ export async function* chatStream( env.NEXT_PUBLIC_STATIC_WEBSITE_ONLY || location.search.includes("mock") || location.search.includes("replay=") - ) { + ) return yield* chatReplayStream(userMessage, params, options); - } - const stream = fetchStream(resolveServiceURL("chat/stream"), { - body: JSON.stringify({ - messages: [{ role: "user", content: userMessage }], - ...params, - }), - signal: options.abortSignal, - }); - for await (const event of stream) { - yield { - type: event.event, - data: JSON.parse(event.data), - } as ChatEvent; + + try{ + const stream = fetchStream(resolveServiceURL("chat/stream"), { + body: JSON.stringify({ + messages: [{ role: "user", content: userMessage }], + ...params, + }), + signal: options.abortSignal, + }); + + for await (const event of stream) { + yield { + type: event.event, + data: JSON.parse(event.data), + } as ChatEvent; + } + }catch(e){ + console.error(e); } }