import * as Sentry from "@sentry/node"; type ValidResult = { type: 'valid'; data: T[]; }; type NotFoundResult = { type: 'notFound'; value: string; }; type CustomResult = ValidResult | NotFoundResult; export function processPromiseResults( results: PromiseSettledResult>[], ): { validItems: T[]; notFoundItems: string[]; } { const validItems: T[] = []; const notFoundItems: string[] = []; results.forEach(result => { if (result.status === 'fulfilled') { const value = result.value; if (value.type === 'valid') { validItems.push(...value.data); } else { notFoundItems.push(value.value); } } }); return { validItems, notFoundItems, }; } export function throwIfAnyFailed(results: PromiseSettledResult[]) { const failedResult = results.find(result => result.status === 'rejected'); if (failedResult) { Sentry.captureException(failedResult.reason); throw failedResult.reason; } }