Skip to content

Commit

Permalink
feat(error): add stacktrace
Browse files Browse the repository at this point in the history
  • Loading branch information
dargmuesli committed Jul 26, 2023
1 parent 3b8e662 commit e84f8cb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
15 changes: 12 additions & 3 deletions components/VioError.vue
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
<template>
<h1>{{ statusCode ? `${statusCode} - ` : '' }}{{ statusReason }}</h1>
<h1>{{ `${statusCode} - ${statusReason}` }}</h1>
<div>
{{ description }}
</div>
<div v-if="stack && !runtimeConfig.public.isInProduction" v-html="stack" />
</template>

<script setup lang="ts">
import { status } from '@http-util/status-i18n'
export interface Props {
statusCode?: number
statusCode: number
statusMessage?: string
description: string
stack?: string
}
const props = withDefaults(defineProps<Props>(), {
statusCode: undefined,
statusMessage: undefined,
stack: undefined,
})
const runtimeConfig = useRuntimeConfig()
const { locale, t } = useI18n()
// computations
Expand Down
16 changes: 9 additions & 7 deletions error.vue
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
<template>
<NuxtLayout>
<VioError
:status-code="error?.statusCode ? +error?.statusCode : undefined"
:status-code="error.statusCode"
:status-message="error.statusMessage"
:description="error.message"
:stack="error.stack"
/>
</NuxtLayout>
</template>

<script setup lang="ts">
export type Error = { statusCode: string }
import { NuxtError } from 'nuxt/app'
export interface Props {
error?: Error
error: NuxtError
}
const props = withDefaults(defineProps<Props>(), {
error: undefined,
})
const props = withDefaults(defineProps<Props>(), {})
useHead({
title: props.error?.statusCode?.toString(),
title: `${props.error.statusCode} - ${props.error.message}`,
})
</script>
1 change: 1 addition & 0 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export default defineNuxtConfig({
runtimeConfig: {
public: {
googleAnalyticsId: '', // set via environment variable `NUXT_PUBLIC_GOOGLE_ANALYTICS_ID` only
isInProduction: process.env.NODE_ENV === 'production',
isTesting: false,
...{
siteName: SITE_NAME,
Expand Down

0 comments on commit e84f8cb

Please sign in to comment.