2022-03-11 08:22:16 +00:00
|
|
|
<template>
|
|
|
|
<ErrorTemplate v-bind="{ statusCode, statusMessage, description, stack }" />
|
|
|
|
</template>
|
|
|
|
|
2022-03-18 10:57:53 +00:00
|
|
|
<script setup>
|
2022-07-15 22:15:31 +00:00
|
|
|
import { defineAsyncComponent } from 'vue'
|
2022-03-11 08:22:16 +00:00
|
|
|
|
2023-05-11 21:54:07 +00:00
|
|
|
const props = defineProps({
|
2024-04-05 18:08:32 +00:00
|
|
|
error: Object,
|
2022-03-11 08:22:16 +00:00
|
|
|
})
|
|
|
|
|
2023-05-11 21:54:07 +00:00
|
|
|
// Deliberately prevent reactive update when error is cleared
|
2023-06-22 09:38:26 +00:00
|
|
|
const _error = props.error
|
2023-05-11 21:54:07 +00:00
|
|
|
|
2022-03-11 08:22:16 +00:00
|
|
|
// TODO: extract to a separate utility
|
2024-02-26 16:08:45 +00:00
|
|
|
const stacktrace = _error.stack
|
|
|
|
? _error.stack
|
|
|
|
.split('\n')
|
|
|
|
.splice(1)
|
|
|
|
.map((line) => {
|
|
|
|
const text = line
|
|
|
|
.replace('webpack:/', '')
|
|
|
|
.replace('.vue', '.js') // TODO: Support sourcemap
|
|
|
|
.trim()
|
|
|
|
return {
|
|
|
|
text,
|
|
|
|
internal: (line.includes('node_modules') && !line.includes('.cache')) ||
|
|
|
|
line.includes('internal') ||
|
2024-04-05 18:08:32 +00:00
|
|
|
line.includes('new Promise'),
|
2024-02-26 16:08:45 +00:00
|
|
|
}
|
|
|
|
}).map(i => `<span class="stack${i.internal ? ' internal' : ''}">${i.text}</span>`).join('\n')
|
|
|
|
: ''
|
2022-03-11 08:22:16 +00:00
|
|
|
|
|
|
|
// Error page props
|
2023-06-22 09:38:26 +00:00
|
|
|
const statusCode = Number(_error.statusCode || 500)
|
2022-07-20 17:00:42 +00:00
|
|
|
const is404 = statusCode === 404
|
2022-03-11 08:22:16 +00:00
|
|
|
|
2023-06-22 09:38:26 +00:00
|
|
|
const statusMessage = _error.statusMessage ?? (is404 ? 'Page Not Found' : 'Internal Server Error')
|
|
|
|
const description = _error.message || _error.toString()
|
2023-08-07 22:03:40 +00:00
|
|
|
const stack = import.meta.dev && !is404 ? _error.description || `<pre>${stacktrace}</pre>` : undefined
|
2022-03-11 08:22:16 +00:00
|
|
|
|
2022-07-15 22:15:31 +00:00
|
|
|
// TODO: Investigate side-effect issue with imports
|
2024-09-10 13:56:08 +00:00
|
|
|
const _Error404 = defineAsyncComponent(() => import('./error-404.vue'))
|
2023-08-07 22:03:40 +00:00
|
|
|
const _Error = import.meta.dev
|
2024-09-10 13:56:08 +00:00
|
|
|
? defineAsyncComponent(() => import('./error-dev.vue'))
|
|
|
|
: defineAsyncComponent(() => import('./error-500.vue'))
|
2022-07-15 22:15:31 +00:00
|
|
|
|
|
|
|
const ErrorTemplate = is404 ? _Error404 : _Error
|
2022-03-11 08:22:16 +00:00
|
|
|
</script>
|