Browse files

Handling invalid_grant and invalid responses when requesting accessToken

  • Loading branch information...
1 parent d5c6e7b commit 1519a216263a21648903f6dea23ebf3dfb27a6ff @matteoagosti committed Jun 28, 2012
Showing with 10 additions and 1 deletion.
  1. +10 −1 lib/node-foursquare.js
View
11 lib/node-foursquare.js
@@ -89,7 +89,16 @@ module.exports = function(config) {
}
else {
try {
- callback(null, JSON.parse(result).access_token);
+ var resultObj = JSON.parse(result);
+ if(resultObj.error) {
+ callback({message: esultObj.error});
+ }
+ else if(!resultObj.access_token) {
+ callback({message: 'access_token not present, got ' + result});
+ }
+ else {
+ callback(null, resultObj.access_token);
+ }
}
catch(e) {
callback(e);

0 comments on commit 1519a21

Please sign in to comment.