-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We realized that the sdk is run on client's server and we can't control the nodejs version or if the have `fetch` polyfill. Also one user saw our sdk failing with TLSSocket.onSocketEnd TypeError terminated other.side closed. The stack trace we saw was pointing to undinci nodejs/undici#583 Which looks is the nodejs fetch implementatin. So we try to use node-fetch to see if this mitigates the error
- Loading branch information
1 parent
9ff7f37
commit df812fe
Showing
6 changed files
with
577 additions
and
478 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
packages/sdks/typescript/src/utils/nodeFetchResponseToReadableStream.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Readable } from 'stream' | ||
|
||
export function nodeFetchResponseToReadableStream(nodeStream: Readable) { | ||
return new ReadableStream({ | ||
start(controller) { | ||
nodeStream.on('data', (chunk: Buffer) => { | ||
controller.enqueue(chunk) | ||
}) | ||
|
||
nodeStream.on('end', () => { | ||
controller.close() | ||
}) | ||
|
||
nodeStream.on('error', (err) => { | ||
controller.error(err) | ||
}) | ||
}, | ||
}) | ||
} |
Oops, something went wrong.