Skip to content

Commit a33fc51

Browse files
lubienegoist
authored andcommitted
fix: fallback to empty array for users with no repos (#26)
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.
1 parent f0a1cb7 commit a33fc51

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

packages/saber-theme-portfolio/src/saber-node.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,22 @@ exports.beforePlugins = async function() {
1515
url: usePinnedRepos
1616
? `https://gh-pinned-repos.now.sh/?username=${github}`
1717
: `https://api.github.com/search/repositories?q=user:${github}&sort:stars&per_page=6`
18+
}).catch(error => {
19+
if (usePinnedRepos) {
20+
throw error
21+
}
22+
23+
// No repos
24+
if (
25+
error.response &&
26+
error.response.status === 422 &&
27+
error.response.data &&
28+
error.response.data.message === 'Validation Failed'
29+
) {
30+
return { data: { items: [] } }
31+
}
32+
33+
throw error
1834
})
1935
])
2036

0 commit comments

Comments
 (0)