Skip to content

Commit

Permalink
Add explicit catches and re-throw errors for every promise
Browse files Browse the repository at this point in the history
This way the promise failures will hopefully become rejections of the
async functions they are in rather than "Uncaught (in promise)" errors
that bubble up to the top.
  • Loading branch information
sirbrillig committed Sep 10, 2024
1 parent 81f5099 commit f251c3a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 18 deletions.
34 changes: 22 additions & 12 deletions src/main/lib/github-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,21 +252,31 @@ export async function fetchNotificationsForAccount(
account,
notification
);
const promise = Promise.all([commentPromise, subjectPromise]);
const promise = Promise.all([commentPromise, subjectPromise]).catch(
(err) => {
throw err;
}
);
promises.push(promise);
promise.then(([commentData, subjectData]) => {
notes.push(
buildNoteFromData({
account,
notification,
subjectData,
commentData,
})
);
});
promise
.then(([commentData, subjectData]) => {
notes.push(
buildNoteFromData({
account,
notification,
subjectData,
commentData,
})
);
})
.catch((err) => {
throw err;
});
}

await Promise.all(promises);
await Promise.all(promises).catch((err) => {
throw err;
});

return notes;
}
16 changes: 10 additions & 6 deletions src/renderer/lib/gitnews-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,16 @@ export function createFetcher(): Middleware<{}, AppReduxState> {
);
const promise = fetchNotifications(account);
promises.push(promise);
promise.then((notes) => {
if ('error' in notes) {
throw notes.error;
}
allNotes = [...allNotes, ...notes];
});
promise
.then((notes) => {
if ('error' in notes) {
throw notes.error;
}
allNotes = [...allNotes, ...notes];
})
.catch((err) => {
throw new Error(err);
});
}

await Promise.all(promises);
Expand Down

0 comments on commit f251c3a

Please sign in to comment.