Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Better error handling.

  • Loading branch information...
commit 0c358542201aab46019000f74cee9444fef00b08 1 parent ea81ac3
Veselin authored

Showing 1 changed file with 8 additions and 13 deletions. Show diff stats Hide diff stats

  1. +8 13 lib/github.js
21 lib/github.js
@@ -42,12 +42,10 @@ github.repos = function(username, cb) {
42 42 var repos = [];
43 43
44 44 github.request(url, function(err, response, body) {
45   - if (response.statusCode == 404) {
46   - throw new Error('Oops. Invalid user.');
47   - }
48   -
49   - if (response.statusCode == 401) {
50   - done(new Error('Oops. Invalid login credentials.'));
  45 + switch (response.statusCode) {
  46 + case 404: throw new Error('Oops. Invalid user.');
  47 + case 401: return done(new Error('Oops. Invalid login credentials.'));
  48 + case 403: throw new Error('Hit GitHub api limit. Try again after few secs.');
51 49 }
52 50
53 51 body.repositories.forEach(function(repo) {
@@ -71,14 +69,11 @@ github.issues = function(username, repos, cb) {
71 69 var url = github.url('issues', { user: username, repo: repo });
72 70
73 71 github.request(url, function(err, response, body) {
74   - if (response.statusCode == 404) {
75   - done(new Error('Oops. Invalid user or repo.'));
76   - }
77   -
78   - if (response.statusCode == 401) {
79   - done(new Error('Oops. Invalid login credentials.'));
  72 + switch (response.statusCode) {
  73 + case 404: return done(new Error('Oops. Invalid user or repo.'));
  74 + case 401: return done(new Error('Oops. Invalid login credentials.'));
  75 + case 403: return done(new Error('Hit GitHub api limit. Try again after few secs.'));
80 76 }
81   -
82 77 results[repo] = body.issues;
83 78 done(err);
84 79 });

0 comments on commit 0c35854

Please sign in to comment.
Something went wrong with that request. Please try again.