-
-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy patherror.vue
147 lines (129 loc) · 3.8 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<script setup lang="ts">
interface ErrorProps {
title: string
statusCode: number
description: string
}
const props = withDefaults(
defineProps<{
error: ErrorProps | null
}>(),
{
error: null,
},
)
const errors = {
400: {
title: "Bad Request",
description: "Bad, bad request!",
},
401: {
title: "Unauthorized",
description:
"This page requires some authorization stuff, or maybe you can't just access this.",
},
403: {
title: "Forbidden",
description: "Maybe you shouldn't be here!",
},
404: {
title: "Page Not Found",
description: "Are you sure you entered a right URL?",
},
500: {
title: "Internal Server Error",
description:
"Lucky. This is not related to you. It's my fault. Please reach me out so that I can fix this issue.",
},
}
useHead({
title: `Error ${props.error?.statusCode}`,
})
/**
* Checks through the common error object and returns the title-description if exists.
* @returns {{title: string, description: string}} The object that contains error title and description.
*/
const getErrorMeta = computed((): { title: string; description: string } => {
const statusCode = props.error?.statusCode
return {
// @ts-ignore-next-line
title: errors[statusCode]?.title || "Unknown",
// @ts-ignore-next-line
description: errors[statusCode]?.description || "No description.",
}
})
onMounted(() => {
console.error(props.error)
})
/**
* Refreshes the page.
*/
const refresh = () => {
window.location.reload()
}
</script>
s
<template>
<div class="min-h-screen bg-gray-50 dark:bg-neutral-900">
<Navbar class="pt-10" />
<!-- Nuxt component -->
<main class="responsive-screen min-h-screen pb-8">
<div class="space-y-4 py-8">
<div class="space-y-2">
<h1 class="text-black/90 dark:text-white/90 font-semibold text-2xl">
An error occured
</h1>
<p class="text-lg text-black/50 dark:text-white/30">
Here are the details:
</p>
</div>
<div class="rounded card-base gap-6 flex flex-col md:flex-row">
<SmartImage
:src="`https://http.cat/${error?.statusCode}.jpg`"
class="rounded w-full md:w-80 flex-shrink-0"
/>
<div class="space-y-6 whitespace-normal">
<div class="flex flex-col space-y-2">
<PageTitle> Title </PageTitle>
<span class="text-black/50 dark:text-white/30">{{
getErrorMeta.title
}}</span>
</div>
<div class="flex flex-col space-y-2">
<PageTitle> Description </PageTitle>
<span class="text-black/50 dark:text-white/30">{{
getErrorMeta.description
}}</span>
</div>
<div class="flex flex-col space-y-2">
<PageTitle> Details </PageTitle>
<pre
class="whitespace-pre-wrap text-black/50 dark:text-white/30"
>{{ JSON.stringify(error, null, 2) }}</pre
>
</div>
</div>
</div>
<div
class="flex items-center justify-between md:justify-start flex-wrap gap-4"
>
<Button icon="heroicons:chevron-left" @click.native="$router.back()"
>Go Back</Button
>
<Button icon="heroicons:arrow-path-solid" @click.native="refresh"
>Refresh Page</Button
>
</div>
</div>
</main>
<!-- Footer -->
<Footer />
<!-- Go to top button -->
<GoTop />
</div>
</template>
<style lang="scss" scoped>
button {
@apply rounded cursor-pointer bg-gray-200 py-2 px-4 transition-colors text-gray-900 select-none dark:bg-neutral-800 dark:text-gray-100 dark:hover:bg-neutral-700 hover:bg-gray-300 focus:outline-none;
}
</style>