thorning / node-mailchimp

node mailchimp wrapper using v3 of the mailchimp api
MIT License
288 stars 35 forks source link

a promise was rejected with a non-error: [object Object] #4

Closed DavidRonNI closed 8 years ago

DavidRonNI commented 8 years ago

index.js line 472. Bluebird promises require an Error instance to be returned, instead the promise is rejected with (response.body) which is not an Error instance.

as such getting the following warning: a promise was rejected with a non-error: [object Object]

solution is probably to wrap the response.body in new Error(response.body.description) or anything that you wish to pass....

thorning commented 8 years ago

You are right, the errors should be wrapped. Do you need to give additional arguments to get the warning?

I would think it should be caught by the following test, but I don't get it:

it('should handle wrong path with promise', function (done) {
    mailchimp.get({
      path : '/wrong',
    }).then(function (result) {
      //Error
      done(result)
    }).catch(function (err) {
      assert.equal(err.status, 404);
      done()
    })
  })

In any case I'll update the library to wrap the errors