Skip to content

Commit

Permalink
Simple error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
David Sanchez authored and David Sanchez committed Feb 7, 2017
1 parent 7474074 commit ae662b9
Showing 1 changed file with 7 additions and 19 deletions.
26 changes: 7 additions & 19 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,6 @@
const fetch = require('node-fetch');
const encode = require('./lib/encode.js');

/* appCredentials Object:
let appCredentials = {
client: {
id: 'CLIENT_ID',
secret: 'CLIENT_SECRET'
},
uri: {
authorization: 'https://someauthorization.com/url',
token: 'https://api.sometoken.com/url',
redirect: 'https://myimportantapp.com/redirect'
},
scope: 'some scope and shit',
responseType: 'code'
}
*/

// oauth.authorizationCodeUri(appCredentials).then((url) => {});
exports.authorizationCodeUri = (appCredentials) => {
return new Promise ((fulfill, reject) => {
if (appCredentials.client.id === undefined) {
Expand All @@ -44,7 +26,13 @@ exports.getAccessToken = (app) => {
},
body: `client_id=${app.client.id}&grant_type=authorization_code&redirect_uri-&${encodeURI(app.uri.redirect)}&code=${app.code}`
}).then((token) => {
fulfill(token.json());
let accessToken = token.json();

if (accessToken.error !== undefined) {
reject(accessToken);
} else {
fulfill(accessToken);
}
}).catch((error) => {
reject(error);
});
Expand Down

0 comments on commit ae662b9

Please sign in to comment.