Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

fix(nuxt): prevent error page rendering a null error #7119

Merged
merged 1 commit into from
Aug 31, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions packages/nuxt/src/app/components/nuxt-error-page.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
<script setup>
import { defineAsyncComponent } from 'vue'

const props = defineProps({
// Deliberately prevent reactive update when error is cleared
// eslint-disable-next-line vue/no-setup-props-destructure
const { error } = defineProps({
error: Object
})

// TODO: extract to a separate utility
const stacktrace = (props.error.stack || '')
const stacktrace = (error.stack || '')
.split('\n')
.splice(1)
.map((line) => {
Expand All @@ -27,12 +29,12 @@ const stacktrace = (props.error.stack || '')
}).map(i => `<span class="stack${i.internal ? ' internal' : ''}">${i.text}</span>`).join('\n')

// Error page props
const statusCode = Number(props.error.statusCode || 500)
const statusCode = Number(error.statusCode || 500)
const is404 = statusCode === 404

const statusMessage = props.error.statusMessage ?? (is404 ? 'Page Not Found' : 'Internal Server Error')
const description = props.error.message || props.error.toString()
const stack = process.dev && !is404 ? props.error.description || `<pre>${stacktrace}</pre>` : undefined
const statusMessage = error.statusMessage ?? (is404 ? 'Page Not Found' : 'Internal Server Error')
const description = error.message || error.toString()
const stack = process.dev && !is404 ? error.description || `<pre>${stacktrace}</pre>` : undefined

// TODO: Investigate side-effect issue with imports
const _Error404 = defineAsyncComponent(() => import('@nuxt/ui-templates/templates/error-404.vue'))
Expand Down