mirror of
https://github.com/all-contributors/cli.git
synced 2025-01-09 21:46:29 +00:00
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
This commit is contained in:
parent
722cc74410
commit
28eb16dea1
2 changed files with 17 additions and 0 deletions
|
@ -13,6 +13,12 @@ module.exports = function getUserInfo(username) {
|
||||||
.then(res => {
|
.then(res => {
|
||||||
var body = JSON.parse(res.body);
|
var body = JSON.parse(res.body);
|
||||||
var profile = body.blog || body.html_url;
|
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;
|
profile = profile.startsWith('http') ? profile : 'http://' + profile;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -10,6 +10,17 @@ test('should handle errors', t => {
|
||||||
return t.throws(getUserInfo('nodisplayname'));
|
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 => {
|
test('should fill in the name when null is returned', t => {
|
||||||
nock('https://api.github.com')
|
nock('https://api.github.com')
|
||||||
.get('/users/nodisplayname')
|
.get('/users/nodisplayname')
|
||||||
|
|
Loading…
Reference in a new issue