-
Notifications
You must be signed in to change notification settings - Fork 1
/
error.vue
85 lines (71 loc) · 1.76 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
<template>
<Html>
<NuxtLayout>
<PageNotFound :status="status" />
</NuxtLayout>
<LazyClientOnly>
<PToast />
</LazyClientOnly>
<LazyClientOnly>
<CookieConsent />
</LazyClientOnly>
</Html>
</template>
<script lang="ts" setup>
import {
onMounted,
} from "vue";
import PToast from "primevue/toast";
import PageNotFound from "~/components/page-not-found.vue";
import {
useQuery,
} from "~/composables/useQuery";
import {
type IInitialDataQuery,
type IInitialDataQueryVariables,
InitialData,
} from "~/graphql/schema";
import {
useTranslationsStore,
} from "~/store/translations";
import {
useUserStore,
} from "~/store/user";
import {
computed,
unref,
useError,
} from "#imports";
import {
useCookieConsentStore,
} from "~/store/cookieConsent";
import CookieConsent from "~/components/nav/CookieConsent.vue";
const translationsStore = useTranslationsStore();
const userStore = useUserStore();
const error = useError();
translationsStore.setLanguageFromCookie();
onMounted(() => {
useCookieConsentStore().fetchConsent();
});
const status = computed((): number => {
const err = unref(error);
if (err instanceof Error) {
return 500;
}
if (!err) {
return 404;
}
return Number(err.statusCode);
});
const initialData = await useQuery<IInitialDataQuery, IInitialDataQueryVariables>({
query: InitialData,
variables: {
language: translationsStore.currentLanguage,
},
})().then((resp) => resp?.data);
console.error(unref(error)?.message);
if (initialData) {
userStore.user = initialData?.profile ?? null;
translationsStore.setTranslations(initialData?.allTranslationsFor ?? []);
}
</script>