From 148d2c9e2372a1db6e70b22e7800857eb7b27f9b Mon Sep 17 00:00:00 2001 From: Lucas Marshall Date: Tue, 12 Dec 2023 12:42:01 -0800 Subject: [PATCH] fix: stream error handling --- packages/core/remotes/utils/paginator.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/core/remotes/utils/paginator.ts b/packages/core/remotes/utils/paginator.ts index c6c34736c9..7c5b2b3ae9 100644 --- a/packages/core/remotes/utils/paginator.ts +++ b/packages/core/remotes/utils/paginator.ts @@ -62,7 +62,7 @@ export async function paginator( 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; @@ -72,13 +72,13 @@ export async function paginator( 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;