Skip to content

Commit

Permalink
fix: Only return null for crawl errors, not all extension in `chromeE…
Browse files Browse the repository at this point in the history
…xtensions`
  • Loading branch information
aklinker1 committed Jul 23, 2024
1 parent cee1c40 commit f5c1c1b
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/services/chrome-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,22 @@ export function createChromeService() {
const loader = createCachedDataLoader<
string,
Gql.ChromeExtension | undefined
>(HOUR_MS, (ids) =>
Promise.all(ids.map((id) => chrome.crawlExtension(id, "en"))),
);
>(HOUR_MS, async (ids) => {
const results = await Promise.allSettled(
ids.map((id) => chrome.crawlExtension(id, "en")),
);
return results.map((res) =>
res.status === "fulfilled" ? res.value : res.reason,
);
});

return {
getExtension: (id: string) => loader.load(id),
getExtensions: async (ids: string[]) => {
const result = await loader.loadMany(ids);
return result.map((item) => {
if (item == null) return undefined;
return result.map((item, index) => {
if (item instanceof Error) {
console.warn("Error fetching multiple extensions:", item);
console.warn("Error loading extension:", ids[index], item);
return undefined;
}
return item;
Expand Down

0 comments on commit f5c1c1b

Please sign in to comment.