fix: add error handling for podcast generation (#59)

Co-authored-by: Jiang Feng <jiangfeng.11@bytedance.com>
This commit is contained in:
Henry Li
2025-05-12 20:56:38 +08:00
committed by GitHub
parent 77a7f8f8ab
commit b845b1ca01
2 changed files with 50 additions and 17 deletions

View File

@@ -294,7 +294,27 @@ export async function listenToPodcast(researchId: string) {
};
appendMessage(podcastMessage);
// Generating podcast...
const audioUrl = await generatePodcast(reportMessage.content);
let audioUrl: string | undefined;
try {
audioUrl = await generatePodcast(reportMessage.content);
} catch (e) {
console.error(e);
useStore.setState((state) => ({
messages: new Map(useStore.getState().messages).set(
podCastMessageId,
{
...state.messages.get(podCastMessageId)!,
content: JSON.stringify({
...podcastObject,
error: e instanceof Error ? e.message : "Unknown error",
}),
isStreaming: false,
},
),
}));
toast("An error occurred while generating podcast. Please try again.");
return;
}
useStore.setState((state) => ({
messages: new Map(useStore.getState().messages).set(podCastMessageId, {
...state.messages.get(podCastMessageId)!,