From 6ea0b58134d58ce339a6cf3c2d7a7e17ec2a6929 Mon Sep 17 00:00:00 2001 From: Heesu Suh Date: Thu, 31 Oct 2024 14:27:59 +0900 Subject: [PATCH] add try catch around youtube parsing (#70) --- src/utils/promptGenerator.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/utils/promptGenerator.ts b/src/utils/promptGenerator.ts index dbfe1ce..d1c0091 100644 --- a/src/utils/promptGenerator.ts +++ b/src/utils/promptGenerator.ts @@ -375,14 +375,17 @@ When writing out new markdown blocks, remember not to include "line_number|" at */ private async getWebsiteContent(url: string): Promise { if (isYoutubeUrl(url)) { - // TODO: pass language based on user preferences - const { title, transcript } = - await YoutubeTranscript.fetchTranscriptAndMetadata(url) - - return `Title: ${title} -Transcript: -${transcript.map((t) => `${t.offset}: ${t.text}`).join('\n')} -` + try { + // TODO: pass language based on user preferences + const { title, transcript } = + await YoutubeTranscript.fetchTranscriptAndMetadata(url) + + return `Title: ${title} +Video Transcript: +${transcript.map((t) => `${t.offset}: ${t.text}`).join('\n')}` + } catch (error) { + console.error('Error fetching YouTube transcript', error) + } } const response = await requestUrl({ url })