diff --git a/src/http-client/fetch-client.ts b/src/http-client/fetch-client.ts index 9377439b..619807cf 100644 --- a/src/http-client/fetch-client.ts +++ b/src/http-client/fetch-client.ts @@ -110,8 +110,15 @@ export class FetchClient implements HTTPClient, HTTPStreamClient { } const reader = body.getReader(); - for await (const line of readLines(reader)) { - yield line; + try { + for await (const line of readLines(reader)) { + yield line; + } + } catch (error) { + throw new NetworkError( + "The network connection encountered a problem while streaming events.", + { cause: error }, + ); } } diff --git a/src/http-client/node-http2-client.ts b/src/http-client/node-http2-client.ts index a8090072..9f69bedf 100644 --- a/src/http-client/node-http2-client.ts +++ b/src/http-client/node-http2-client.ts @@ -205,7 +205,12 @@ export class NodeHTTP2Client implements HTTPClient, HTTPStreamClient { .request(httpRequestHeaders) .setEncoding("utf8") .on("error", (error: any) => { - rejectPromise(error); + rejectPromise( + new NetworkError( + "The network connection encountered a problem while streaming events.", + { cause: error }, + ), + ); }) .on("response", onResponse); @@ -218,7 +223,12 @@ export class NodeHTTP2Client implements HTTPClient, HTTPStreamClient { req.end(); } catch (error) { - rejectPromise(error); + rejectPromise( + new NetworkError( + "The network connection encountered a problem while streaming events.", + { cause: error }, + ), + ); } }); }