mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-19 01:45:53 +00:00
chore(nuxt): prevent error page rendering a null error (#7119)
This commit is contained in:
parent
0339a23372
commit
d7b2d32b5e
@ -5,12 +5,14 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { defineAsyncComponent } from 'vue'
|
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
|
error: Object
|
||||||
})
|
})
|
||||||
|
|
||||||
// TODO: extract to a separate utility
|
// TODO: extract to a separate utility
|
||||||
const stacktrace = (props.error.stack || '')
|
const stacktrace = (error.stack || '')
|
||||||
.split('\n')
|
.split('\n')
|
||||||
.splice(1)
|
.splice(1)
|
||||||
.map((line) => {
|
.map((line) => {
|
||||||
@ -27,12 +29,12 @@ const stacktrace = (props.error.stack || '')
|
|||||||
}).map(i => `<span class="stack${i.internal ? ' internal' : ''}">${i.text}</span>`).join('\n')
|
}).map(i => `<span class="stack${i.internal ? ' internal' : ''}">${i.text}</span>`).join('\n')
|
||||||
|
|
||||||
// Error page props
|
// Error page props
|
||||||
const statusCode = Number(props.error.statusCode || 500)
|
const statusCode = Number(error.statusCode || 500)
|
||||||
const is404 = statusCode === 404
|
const is404 = statusCode === 404
|
||||||
|
|
||||||
const statusMessage = props.error.statusMessage ?? (is404 ? 'Page Not Found' : 'Internal Server Error')
|
const statusMessage = error.statusMessage ?? (is404 ? 'Page Not Found' : 'Internal Server Error')
|
||||||
const description = props.error.message || props.error.toString()
|
const description = error.message || error.toString()
|
||||||
const stack = process.dev && !is404 ? props.error.description || `<pre>${stacktrace}</pre>` : undefined
|
const stack = process.dev && !is404 ? error.description || `<pre>${stacktrace}</pre>` : undefined
|
||||||
|
|
||||||
// TODO: Investigate side-effect issue with imports
|
// TODO: Investigate side-effect issue with imports
|
||||||
const _Error404 = defineAsyncComponent(() => import('@nuxt/ui-templates/templates/error-404.vue'))
|
const _Error404 = defineAsyncComponent(() => import('@nuxt/ui-templates/templates/error-404.vue'))
|
||||||
|
Loading…
Reference in New Issue
Block a user