Skip to content

Commit e9d554b

Browse files
committed
fix: fetch stargazers
1 parent 89e299c commit e9d554b

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/pages/index.tsx

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,20 @@ export const HomePage = (props: InferGetStaticPropsType<typeof getStaticProps>)
2929
export default HomePage;
3030

3131
export const getStaticProps = (async () => {
32-
const res = await fetch("https://api.github.com/repos/AykutSarac/jsoncrack.com");
33-
const data = await res.json();
32+
try {
33+
const res = await fetch("https://api.github.com/repos/AykutSarac/jsoncrack.com");
34+
const data = await res.json();
3435

35-
return {
36-
props: {
37-
stars: data.stargazers_count,
38-
},
39-
};
36+
return {
37+
props: {
38+
stars: data?.stargazers_count || 0,
39+
},
40+
};
41+
} catch (error) {
42+
return {
43+
props: {
44+
stars: 0,
45+
},
46+
};
47+
}
4048
}) satisfies GetStaticProps<{ stars: number }>;

0 commit comments

Comments
 (0)