Skip to content

fix: make FetchResponse type compatible with a native Response object #1025

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"compilerOptions": {
"alwaysStrict": true,
"checkJs": true,
"maxNodeModuleJsDepth": 0,
"module": "commonjs",
"noEmit": true,
"noImplicitOverride": true,
Expand Down
15 changes: 12 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"@commitlint/config-conventional": "^19.1.0",
"@financial-times/eslint-config-next": "^7.1.0",
"@types/jest": "^29.5.12",
"@types/node": "^20.12.7",
"eslint": "^8.57.0",
"eslint-plugin-jsdoc": "^48.2.1",
"eslint-plugin-prettier": "^5.1.3",
Expand Down
6 changes: 4 additions & 2 deletions packages/fetch-error-handler/lib/create-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const { Writable } = require('node:stream');
*/

/**
* @typedef {object} FetchResponseBody
* @typedef {object} NodeFetchResponseBody
* @property {(stream: Writable) => void} [pipe]
* A function to pipe a response body stream.
*/
Expand All @@ -25,7 +25,7 @@ const { Writable } = require('node:stream');
* The response HTTP status code.
* @property {string} url
* The URL of the response.
* @property {FetchResponseBody} body
* @property {NodeFetchResponseBody | ReadableStream<Uint8Array> | null} body
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ReadableStream here is the native web streams type, which comes from the DOM lib types. i'm not 100% certain how this will behave if the consumer doesn't have that lib.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually this seems to work fine in cp-content-pipeline-schema

* A representation of the response body.
*/

Expand Down Expand Up @@ -205,6 +205,8 @@ function createFetchErrorHandler(options = {}) {
// body so we don't introduce a memory leak.
if (
isFetchResponse(response) &&
response.body &&
'pipe' in response.body &&
typeof response.body.pipe === 'function'
) {
response.body.pipe(new BlackHoleStream());
Expand Down
Loading