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 (#2054)
Browse files Browse the repository at this point in the history
Node documentation indicates that this is the correct way to indicate
errors in a stream and not to use `.emit('error', ...)` as that is
internal to streams.

I'm hoping this will fix some cases were we aren't getting errors
handled by the `handleErr` function in the provider.
  • Loading branch information
lucasmarshall authored Dec 12, 2023
1 parent 7dd1471 commit e81f636
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 e81f636

Please sign in to comment.