request/request-promise

poor error message

notslang opened this issue · 12 comments

When an error occurs in a request, I get this printed out (directly after whatever error message I print for the error):

/usrdata/web/facebook-insights-cli/node_modules/request-promise/node_modules/bluebird/js/main/async.js:36
        fn = function () { throw arg; };
                                 ^
TypeError: undefined is not a function
  at module.exports (/usrdata/web/facebook-insights-cli/node_modules/request-promise/lib/rp.js:158:9)
  at Function.CapturedTrace.fireRejectionEvent (/usrdata/web/facebook-insights-cli/node_modules/request-promise/node_modules/bluebird/js/main/captured_trace.js:214:17)
  at Promise._notifyUnhandledRejection (/usrdata/web/facebook-insights-cli/node_modules/request-promise/node_modules/bluebird/js/main/promise.js:889:23)
  at Async._drainQueue (/usrdata/web/facebook-insights-cli/node_modules/request-promise/node_modules/bluebird/js/main/async.js:84:12)
  at Async._drainQueues (/usrdata/web/facebook-insights-cli/node_modules/request-promise/node_modules/bluebird/js/main/async.js:91:10)
  at Async.drainQueues (/usrdata/web/facebook-insights-cli/node_modules/request-promise/node_modules/bluebird/js/main/async.js:14:14)
  at process._tickCallback (node.js:419:13)

...which isn't very helpful.

Good find. Thanks!

Could you give me some example code so I can write a test for it?

Don't mind. I found it. Two tests are already failing when executed with the latest version of Bluebird.

I will release a fix shortly.

What you actually observe is the aftermath of a possibly unhandled rejection. This is a bug in request-promise, however, you probably should handle those rejections.

If you just use:

rp(...).then(function (body) { ... });

...you should also use a catch like this:

rp(...)
    .then(function (body) { ... })
    .catch(function (reason) { ... });

The catch function will handle any rejection and you won't run into the bug anymore.

I was actually getting that output even if I was using .catch to handle the error.

Oh, that is bad! Can you give me some example code so I can fix that more quickly?

It was just:

request.get(
  uri: url
  qs: queryString
).then((body) ->
  JSON.parse(body).data
).catch((err) ->
  console.error err
)

...I would give more context, but the project is a mess right now because I'm just experimenting with the facebook API, and it should be a pretty standard call.

Unfortunately, I can't reproduce the error when catch is used.
Could you give me the output of console.dir( uri: url, qs: queryString )?

Hey @slang800 I just published request-promise@0.3.3 to npm.
Could you do me a huge favor and test if you now get good error messages in all of your cases? Thanks!

Hi @slang800 since I wasn't able to reproduce all your issues it would be awesome if you could check whether some issues still remain with the latest version. Thanks!

Sure. I temporarily removed request-promise & just used request wrapped by when.JS, but I'll swap that out tomorrow morning & make sure it's fixed.

Ok, I tested it out and it seems to work! thanks!

Thank you very much!