xhr icon indicating copy to clipboard operation
xhr copied to clipboard

Add warning where request/request compatible code would silently fail

Open naugtur opened this issue 10 years ago • 6 comments

request has some options that would be silently ignored if one tried to use them with xhr, eg.

requestORxhr({
  url: "http://google.com",
  qs: {
    q: "how do I search internet?"
  }
})

request will send the query, but xhr doesn't support qs (if it should is a totally different matter, we keep the size small)

Proposal: run console.warn(optionKey+' option not implemented')

naugtur avatar Dec 12 '14 20:12 naugtur

ya don't need to add extra overhead of supporting querystring.

if someone wants that they should use a shitty-qs or something like it

reqshark avatar Dec 12 '14 20:12 reqshark

I mean the other way around than shitty-qs works, but that's the main point - you can use anything to put query params in the url (I like how Array.join works for that :P) But this is just an example and I'd like to list all options that exist in request and are not supported, and then throw warnings if someone uses them. The size increase should not be that bad - bytes for the list + ~3 lines of code.

naugtur avatar Dec 12 '14 20:12 naugtur

@naugtur

console warnings break the unix rule of silence.

If you want to warn the user, throw an exception.

Raynos avatar Dec 12 '14 20:12 Raynos

Ok, thanks for the reminder. I always had trouble following the rule of silence in my ideas...

naugtur avatar Dec 12 '14 21:12 naugtur

In the browser, I think console warnings are better than giving no indication. I've added that in one of my own libraries and been very glad I did, it's saved me a good amount of debugging time.

Throwing an exception is fine too. It seems like overly-aggressive duck typing in the browser - in the browser I'm more willing to allow warnings instead of exceptions in cases like this - but I would support throwing an error in the case of input options that aren't implemented.

TehShrike avatar Jun 01 '16 03:06 TehShrike

It's a hard decision. Sometimes, when you're reusing code between node and browser and put xhr in place of request you want certain features to only work in node.

I was thinking we could expose a xhr.registerWarningCallback function where you could pass console.warn or anything you like.

naugtur avatar Jun 01 '16 07:06 naugtur