Skip to content

Commit 6cbc6b7

Browse files
committed
add error logging to get web search results
1 parent d504539 commit 6cbc6b7

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

apps/hash-ai-worker-ts/src/activities/flow-activities/web-search-action.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import type { GetWebSearchResults200ResponseWebSearchResultsInner } from "@local
66
import { StatusCode } from "@local/status";
77
import { backOff } from "exponential-backoff";
88

9+
import { logger } from "../shared/activity-logger.js";
10+
911
export type GetWebSearchResultsResponse = Omit<
1012
GetWebSearchResults200ResponseWebSearchResultsInner,
1113
"url"
@@ -30,11 +32,25 @@ export const webSearchAction: AiFlowActionActivity<"webSearch"> = async ({
3032

3133
const {
3234
data: { webSearchResults },
33-
} = await backOff(() => internalApiClient.getWebSearchResults(query), {
34-
jitter: "full",
35-
numOfAttempts: 3,
36-
startingDelay: 1_000,
37-
});
35+
} = await backOff(
36+
async () => {
37+
try {
38+
return await internalApiClient.getWebSearchResults(query);
39+
} catch (error) {
40+
logger.error(
41+
`Error fetching web search results for query "${query}": ${
42+
error instanceof Error ? error.message : JSON.stringify(error)
43+
}`,
44+
);
45+
throw error;
46+
}
47+
},
48+
{
49+
jitter: "full",
50+
numOfAttempts: 3,
51+
startingDelay: 1_000,
52+
},
53+
);
3854

3955
const webPages = webSearchResults.slice(0, numberOfSearchResults);
4056

0 commit comments

Comments
 (0)