Skip to content

Commit

Permalink
fix:all-contributors#6 added common error handling for username not p…
Browse files Browse the repository at this point in the history
…rovided or wrong username provided.
  • Loading branch information
erdahuja committed Feb 23, 2019
1 parent e0240de commit 295ca33
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/contributors/prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ function getQuestions(options, username, contributions) {
options.repoType,
)} username?`,
when: !username,
validate: function validate(input) {
if (!input) {
return 'Username not provided'
}
return true
},
},
{
type: 'checkbox',
Expand Down Expand Up @@ -88,7 +94,6 @@ function getValidUserContributions(options, contributions) {
`${invalidUserContributions.toString()} is/are invalid contribution type(s)`,
)
}

return validUserContributions
}

Expand Down
10 changes: 9 additions & 1 deletion src/repo/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ const getUserInfo = function(username, hostname, optionalPrivateToken) {
hostname = 'https://github.com'
}

if (!username) {
throw new Error(
`No login when adding a contributor. Please spicy a username.`,
)
}

const root = hostname.replace(/:\/\//, '://api.')
return request
.get({
Expand All @@ -72,7 +78,9 @@ const getUserInfo = function(username, hostname, optionalPrivateToken) {

// Github throwing specific errors as 200...
if (!profile && body.message) {
throw new Error(body.message)
throw new Error(
`Login not found when adding a contributor for username - ${username}.`,
)
}

profile = profile.startsWith('http') ? profile : `http://${profile}`
Expand Down

0 comments on commit 295ca33

Please sign in to comment.