Skip to content
This repository has been archived by the owner on Mar 10, 2024. It is now read-only.

Commit

Permalink
fix: stream error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmarshall committed Dec 12, 2023
1 parent 49e4b59 commit 148d2c9
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/core/remotes/utils/paginator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export async function paginator<T>(
response = await pageFetcher(cursor);
} catch (e: any) {
if (e.problemType === 'SG_TERMINAL_TOO_MANY_REQUESTS_ERROR') {
passThrough.emit('error', e);
passThrough.destroy(e);
return;
}
throw e;
Expand All @@ -72,13 +72,13 @@ export async function paginator<T>(
cursor = getNextCursorFromPage(response);

readable.pipe(passThrough, { end: index === lastIndex && !cursor });
readable.on('error', (err) => passThrough.emit('error', err));
readable.on('error', (err) => passThrough.destroy(err));

await new Promise((resolve) => readable.on('end', resolve));
} while (cursor);
}
})().catch((err) => {
passThrough.emit('error', err);
passThrough.destroy(err);
});

return passThrough;
Expand Down

0 comments on commit 148d2c9

Please sign in to comment.