Skip to content

Commit

Permalink
fix: github accessible check
Browse files Browse the repository at this point in the history
  • Loading branch information
monkeyWie committed Jul 30, 2023
1 parent 07e3efb commit 1409223
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions components/HeroSection.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ const HeroSection = ({ release }) => {
const [downloadUrl, setDownloadUrl] = useState('')

useEffect(() => {
setGithubAccessible(true)
if (!isCn) {
setGithubAccessible(true)
return
}
fetch('https://api.github.com').catch(() => {
setGithubAccessible(false)
// check github accessible
Promise.race([fetch('https://github.com'), new Promise((_, reject) => setTimeout(() => reject(new Error('timeout')), 1000))]).catch((e) => {
if (e.message === 'timeout') {
setGithubAccessible(false)
}
})
}, [isCn])

Expand Down

0 comments on commit 1409223

Please sign in to comment.