Skip to content

Commit

Permalink
fix: throw error when Github returns 200s for specific errors. (#52)
Browse files Browse the repository at this point in the history
* Added exception handling when github returns 200s that have hit rate-limiting

* Hardened the error check a bit
  • Loading branch information
brycereynolds authored and Kent C. Dodds committed Oct 19, 2017
1 parent 722cc74 commit 28eb16d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/contributors/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ module.exports = function getUserInfo(username) {
.then(res => {
var body = JSON.parse(res.body);
var profile = body.blog || body.html_url;

// Github throwing specific errors as 200...
if (!profile && body.message) {
throw new Error(body.message);
}

profile = profile.startsWith('http') ? profile : 'http://' + profile;

return {
Expand Down
11 changes: 11 additions & 0 deletions lib/contributors/github.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ test('should handle errors', t => {
return t.throws(getUserInfo('nodisplayname'));
});

test('should handle github errors', t => {
nock('https://api.github.com')
.get('/users/nodisplayname')
.reply(200, {
message: 'API rate limit exceeded for 0.0.0.0. (But here\'s the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)',
documentation_url: 'https://developer.github.com/v3/#rate-limiting'
});

return t.throws(getUserInfo('nodisplayname'));
});

test('should fill in the name when null is returned', t => {
nock('https://api.github.com')
.get('/users/nodisplayname')
Expand Down

0 comments on commit 28eb16d

Please sign in to comment.