cronofy / cronofy-node

Node wrapper for the Cronofy API
https://docs.cronofy.com/developers
MIT License
49 stars 23 forks source link

Potentially unhandled rejection [4] [object Object] (WARNING: non-Error used) #12

Closed adenta closed 8 years ago

adenta commented 8 years ago

Whenever I try to get an auth token, I am seeing this error.

Is this common? What might be causing me to not be able to authenticate a user?

Code: (with the id and secret from the cronofy website replaced with placeholders.)

app.get('/cal',function(req,res){
  var options = {
    client_id: 'CLIENT_STRING',
    client_secret: 'CLIENT_SECRET',
    grant_type: 'authorization_code',
    code: req.query.code,
    redirect_uri: 'http://localhost:5000'
  };

  cronofy.requestAccessToken(options)
      .then(function(response){
          console.log(response);
          res.json(response);
        });

});

warbrett commented 8 years ago

There are a few things that could be causing an error, the most common one I see is when the redirect_uri isn't an exact match though.

The reason you're not seeing the full error is because you need to catch it at the end of the promise chain. So if you were to do:

  cronofy.requestAccessToken(options)
      .then(function(response){
          console.log(response);
          res.json(response);
        }).catch(console.log);

You should be able to read it in your terminal and get a better idea of where it's going wrong. Alternatively you can use the method with a callback function that has an error as the first argument if you're more comfortable with callbacks, for example:

cronofy.requestAccessToken(options, function(err, res){
   if(err) {
     console.log(err)
    }
   res.json(response);
})

Let me know if that helps at all!

warbrett commented 8 years ago

I'm going to go ahead and close this one since I haven't heard anything back and I'm unable to find any bugs locally. However don't hesitate to open another issue or reach out if you run into any more problems!