Skip to content

Commit

Permalink
wrap errors in NetworkError
Browse files Browse the repository at this point in the history
  • Loading branch information
ptpaterson committed Apr 17, 2024
1 parent 3180e45 commit d25d0f3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
11 changes: 9 additions & 2 deletions src/http-client/fetch-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
);
}
}

Expand Down
14 changes: 12 additions & 2 deletions src/http-client/node-http2-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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 },
),
);
}
});
}
Expand Down

0 comments on commit d25d0f3

Please sign in to comment.