Skip to content

Commit 1ecd19f

Browse files
author
Akshay
committed
Added feature for OAuth Authentication Token and error template.
1 parent 064efcf commit 1ecd19f

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

src/github.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,16 +327,22 @@
327327
},
328328

329329
getData: function(url, options, callback){
330-
// Utility for synchronous AJAX calls
330+
// Utility for asynchronous AJAX calls
331331
var data, request;
332332
request = new XMLHttpRequest();
333333
request.open('GET', url, true);
334-
334+
// Use OAuth token if available
335+
if (options.OAuth) {
336+
request.setRequestHeader('Authorization', 'Token ' + options.OAuth);
337+
}
338+
335339
request.onload = function(e) {
336340
if (request.status >= 200 && request.status < 400){
337341
data = JSON.parse(request.responseText);
338342
callback(data, options);
339343
} else {
344+
// Unsuccessful request - invalid username/lost internet connectivity/exceeded rate limit/API URL not found
345+
gitMethods.renderContent(gitMethods.getRenderedHTML(gitTemplates.notFoundTpl, data), options.selector,'.gt-container');
340346
console.error('An error occurred while connecting to GitHub API.');
341347
}
342348
};

0 commit comments

Comments
 (0)