From 28eb16dea16efcd83e0cf12289d21051b3e35e11 Mon Sep 17 00:00:00 2001 From: Bryce Reynolds Date: Thu, 19 Oct 2017 11:59:09 -0700 Subject: [PATCH] fix: throw error when Github returns 200s for specific errors. (#52) * Added exception handling when github returns 200s that have hit rate-limiting * Hardened the error check a bit --- lib/contributors/github.js | 6 ++++++ lib/contributors/github.test.js | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/lib/contributors/github.js b/lib/contributors/github.js index 0e77ac48..1c51dc87 100644 --- a/lib/contributors/github.js +++ b/lib/contributors/github.js @@ -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 { diff --git a/lib/contributors/github.test.js b/lib/contributors/github.test.js index c3df530b..297ab7eb 100644 --- a/lib/contributors/github.test.js +++ b/lib/contributors/github.test.js @@ -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')