-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.vue
71 lines (66 loc) · 1.86 KB
/
error.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<template>
<div class="flex h-screen flex-col items-center justify-center gap-8 divide-x sm:flex-row">
<h1>{{ error.statusCode ?? "Error" }}</h1>
<div class="pl-8">
<h2 class="whitespace-pre">{{ errorTitle }}</h2>
<div v-if="error.message">
<p>{{ error.message }}</p>
</div>
<UButton to="/" label="Go back" class="mt-2" />
</div>
</div>
</template>
<script lang="ts">
import { type NuxtError } from "#app";
export default defineComponent({
layout: "default",
props: {
error: {
type: Object as () => NuxtError,
required: true,
},
},
setup(props) {
const friendlyErrorStatus: { [key: number]: string } = {
400: "Bad Request",
401: "Unauthorized",
402: "Payment Required",
403: "Forbidden",
404: "Not Found",
405: "Method Not Allowed",
406: "Not Acceptable",
407: "Proxy Authentication Required",
408: "Request Timeout",
409: "Conflict",
410: "Gone",
411: "Length Required",
412: "Precondition Required",
413: "Request Entry Too Large",
414: "Request-URI Too Long",
415: "Unsupported Media Type",
416: "Requested Range Not Satisfiable",
417: "Expectation Failed",
418: "I'm a teapot",
429: "Too Many Requests",
500: "Internal Server Error",
501: "Not Implemented",
502: "Bad Gateway",
503: "Service Unavailable",
504: "Gateway Timeout",
505: "HTTP Version Not Supported",
};
const errorTitle = computed(() => {
if (props.error.statusCode && props.error.statusCode in friendlyErrorStatus) {
return friendlyErrorStatus[props.error.statusCode] ?? "Error";
}
return "An unknown error occured";
});
return { errorTitle };
},
});
</script>
<style lang="postcss" scoped>
h1 {
@apply text-6xl font-bold text-indigo-600;
}
</style>