Skip to content

Commit

Permalink
fix: fallback to empty array for users with no repos (#26)
Browse files Browse the repository at this point in the history
GitHub return HTTP error 422 when you search
for repos from an user with no repos.

This approach detects it and return an empty array
to properly be handled later.
  • Loading branch information
lubien authored and egoist committed Jun 25, 2019
1 parent f0a1cb7 commit a33fc51
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/saber-theme-portfolio/src/saber-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,22 @@ exports.beforePlugins = async function() {
url: usePinnedRepos
? `https://gh-pinned-repos.now.sh/?username=${github}`
: `https://api.github.com/search/repositories?q=user:${github}&sort:stars&per_page=6`
}).catch(error => {
if (usePinnedRepos) {
throw error
}

// No repos
if (
error.response &&
error.response.status === 422 &&
error.response.data &&
error.response.data.message === 'Validation Failed'
) {
return { data: { items: [] } }
}

throw error
})
])

Expand Down

0 comments on commit a33fc51

Please sign in to comment.