Skip to content

Commit

Permalink
chore: better error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
atinux committed Oct 16, 2023
1 parent 0b12d84 commit ac397ed
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion components/AppHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ defineProps<{
icon="i-simple-icons-github"
to="https://github.com/nuxt/nuxt"
target="_blank"
:label="formatNumber(stats.stars)"
:label="stats ? formatNumber(stats.stars) : '...'"
v-bind="($ui.button.secondary as any)"
/>
</UTooltip>
Expand Down
5 changes: 0 additions & 5 deletions plugins/stats.server.ts

This file was deleted.

12 changes: 12 additions & 0 deletions plugins/stats.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default defineNuxtPlugin(async () => {
const stats = useStats()

if (process.server) {
stats.value = await $fetch('https://api.nuxt.com/stats').catch(() => null)
}
onNuxtReady(async () => {
if (!stats.value) {
stats.value = await $fetch('https://api.nuxt.com/stats')
}
})
})

0 comments on commit ac397ed

Please sign in to comment.