Skip to content

Add req res data warn#1333

Closed
TheGLander wants to merge 5 commits into
node-fetch:mainfrom
TheGLander:add-req-res-data-warn
Closed

Add req res data warn#1333
TheGLander wants to merge 5 commits into
node-fetch:mainfrom
TheGLander:add-req-res-data-warn

Conversation

@TheGLander

@TheGLander TheGLander commented Oct 9, 2021

Copy link
Copy Markdown
Contributor

What is the purpose of this pull request?

  • Documentation update
  • Bug fix
  • New feature
  • Other, please explain:

What changes did you make? (provide an overview)

Added a one-time warning for when .data is used in any way, as a way to help porting from other libraries for requests (such as axios).

Which issue (if any) does this pull request address?

Closes #1000

@jimmywarting

Copy link
Copy Markdown
Collaborator

Thinking maybe if we could use https://nodejs.org/dist/latest-v16.x/docs/api/util.html#util_util_deprecate_fn_msg_code

It is a one time warning function...

@TheGLander

Copy link
Copy Markdown
Contributor Author

I feel like that's more for deprecated functions specifically, due to the node flags for it. Plus, I can't really see how exactly the deprecation function would be used here, unless No-op functions are used, but that kinda defeats the purpose of the deprecation wrapper.

@jimmywarting

Copy link
Copy Markdown
Collaborator

I thought so too... But it's mere elegant in a way also. + We are already using it

@TheGLander

Copy link
Copy Markdown
Contributor Author

I tried using the deprecate wrapper just now, and it's kinda hard to test for, should I remove the warn tests, as they aren't that critical? I don't think there is a good way of checking for 'warning' events in the scenario the tests are in...

@jimmywarting

Copy link
Copy Markdown
Collaborator

we don't have a test for the other warning message about res.buffer() and the old form-data... but i think there is the process.on('warning', fn) that one could use to test something...

https://www.geeksforgeeks.org/node-js-process-warning-event/

@TheGLander

Copy link
Copy Markdown
Contributor Author

Changed the tests and the warnings to use the deprecate API.

Comment thread src/response.js
clone: {enumerable: true},
data: {get: deprecate(() => {},
'.data is not a valid Response property, use .json(), .text(), .arrayBuffer(), or .body instead',
'https://github.com/node-fetch/node-fetch/issues/1000 (response)')}

@jimmywarting jimmywarting Oct 13, 2021

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

overall i like this PR but wonder if not this getter fn should not be in the body mixin instead.

It's possible to use the Request too new Request(url, {body}).arrayBuffer()
all doe i don't thing anyone will make that misstake... seems almost unnecessary, nobody would do: new Request().data or assigning a value onto it...

Comment thread test/request.js Outdated

@LinusU LinusU left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Neat 👍

@jimmywarting jimmywarting mentioned this pull request Dec 19, 2021
1 task
@jimmywarting

Copy link
Copy Markdown
Collaborator

made some small changes to this in #1421

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hint that using data is wrong

3 participants