-
Notifications
You must be signed in to change notification settings - Fork 5
/
error.vue
60 lines (52 loc) · 1.32 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
<script setup lang="ts">
import { Error } from '#components'
const props = defineProps({
error: {
type: Object,
default() {
return {}
},
},
})
const config = useAppConfig()
const url = computed(() => {
// eslint-disable-next-line eqeqeq
return props.error.statusCode == 404 ? '/' : props.error.url
})
interface ErrorMessage {
message: string
key: string
img: string
alt: string
}
function getError(code: number): ErrorMessage {
const msg: ErrorMessage = {
message: 'An error occurred!',
alt: 'An error occurred!',
img: `${config.cloudinaryURL}/assets/svg/web/error.svg`,
key: 'error.unknown',
}
switch (code) {
case 404:
msg.message = 'Page not found!'
msg.key = 'error.pagenotfound'
msg.alt = '404 Not Found!'
msg.img = `${config.cloudinaryURL}/assets/svg/web/404.svg`
break
case 503:
msg.message = 'Service temporarily unavailable, Try again later!'
msg.alt = '503 Service Unavailable!'
msg.key = 'error.unavailable'
break
}
return msg
}
const errorMessage = computed<ErrorMessage>(() => {
return getError(Number(props.error.statusCode))
})
</script>
<template>
<NuxtLayout>
<Error :message="$t(errorMessage.key)" :alt="$t(errorMessage.key)" :img-src="errorMessage.img" :url="url" />
</NuxtLayout>
</template>