Skip to content

Commit

Permalink
feat: add error component
Browse files Browse the repository at this point in the history
  • Loading branch information
dargmuesli committed Apr 12, 2023
1 parent d5b8b98 commit ffc5205
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
28 changes: 28 additions & 0 deletions components/VioError.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<template>
<h1>{{ statusCode ? `${statusCode} - ` : '' }}{{ statusReason }}</h1>
</template>

<script setup lang="ts">
import { status } from '@http-util/status-i18n'
export interface Props {
statusCode?: number
}
const props = withDefaults(defineProps<Props>(), {
statusCode: undefined,
})
const { locale, t } = useI18n()
// computations
const statusReason = computed(() => {
return status(props.statusCode, locale) || t('error')
})
</script>

<i18n lang="yaml">
de:
error: Fehler
en:
error: Error
</i18n>
21 changes: 21 additions & 0 deletions error.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<template>
<NuxtLayout>
<VioError
:status-code="error?.statusCode ? +error?.statusCode : undefined"
/>
</NuxtLayout>
</template>
<script setup lang="ts">
export type Error = { statusCode: string }
export interface Props {
error?: Error
}
const props = withDefaults(defineProps<Props>(), {
error: undefined,
})
useHead({
title: props.error?.statusCode?.toString(),
})
</script>
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
},
"dependencies": {
"@dargmuesli/nuxt-cookie-control": "5.4.0",
"@http-util/status-i18n": "0.6.2",
"@nuxtjs/html-validator": "1.2.4",
"@nuxtjs/i18n": "8.0.0-beta.10",
"@nuxtjs/tailwindcss": "6.6.5",
Expand Down
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ffc5205

Please sign in to comment.