Skip to content

Hint that using data is wrong #1000

@jimmywarting

Description

@jimmywarting

From time to time i see ppl using data instead of body which is wrong.
happened just recently in #481 (comment)

how do you feel about adding a little warning message that can only appear once. (kinda like node reports that you are using experimental apis)

if ('data' in bodyInit && notWarned) {
  console.warn('use body instead')
}
class Response {
  get data () {
    notWarned && console.warn('you want to use .json(), .text(), .arrayBuffer() or just .body')
  }
}

I don't think it is uncommon to see those mistake happening when switching from different request libraries axios use data instead of body for example. I can admit that i have used data as well and wasted minutes trying to figure out what's wrong

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions