Skip to content

Commit

Permalink
Changed error handling on related query
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaoroger committed Nov 22, 2024
1 parent 5b85762 commit 5cf6e13
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions libs/langchain-community/src/tools/google_trends.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]}`,
Expand Down

0 comments on commit 5cf6e13

Please sign in to comment.