Skip to content

Commit 5a0e47e

Browse files
committed
Fix error handling
1 parent 35533f3 commit 5a0e47e

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

apps/landing/src/app/StarButton.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,17 @@ export default function StarButton() {
1313
const abortController = new AbortController()
1414
const fetchStarCount = async () => {
1515
try {
16-
const res = await fetch(
16+
const data = await fetch(
1717
'https://api.github.com/repos/dev-five-git/devup-ui',
1818
{
1919
signal: abortController.signal,
2020
},
21-
)
22-
const data = await res.json()
21+
).then((res) => res.json())
2322
setStarCount(data.stargazers_count)
2423
} catch (error) {
2524
console.error(error)
25+
} finally {
26+
setStarCount((prev) => (typeof prev === 'number' ? prev : -1))
2627
}
2728
}
2829
fetchStarCount()

0 commit comments

Comments
 (0)