diff --git a/libs/langchain-community/src/tools/google_trends.ts b/libs/langchain-community/src/tools/google_trends.ts index 08ceae35dc49e..461dd9594661d 100644 --- a/libs/langchain-community/src/tools/google_trends.ts +++ b/libs/langchain-community/src/tools/google_trends.ts @@ -106,20 +106,23 @@ export class GoogleTrendsAPI extends Tool { } ); + let rising = []; + let top = []; if (!relatedRes.ok) { - throw new Error( + console.error( `Error fetching related queries from SerpAPI: ${relatedRes.statusText}` ); + } else { + const relatedDict = await relatedRes.json(); + rising = + relatedDict.related_queries?.rising?.map( + (result: any) => result.query + ) ?? []; + top = + relatedDict.related_queries?.top?.map((result: any) => result.query) ?? + []; } - const relatedDict = await relatedRes.json(); - const rising = - relatedDict.related_queries?.rising?.map((result: any) => result.query) ?? - []; - const top = - relatedDict.related_queries?.top?.map((result: any) => result.query) ?? - []; - const doc = [ `Query: ${query}`, `Date From: ${startDate[0]} ${startDate[1]}, ${startDate[2]}`,