Skip to content

Commit

Permalink
Error handling improvements & fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
steel97 committed Jan 30, 2024
1 parent 9810f37 commit 7413897
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 31 deletions.
30 changes: 16 additions & 14 deletions src/app.vue
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
<template>
<NuxtLayout>
<div class="text-gray-700">
<div class="fg"></div>
<AppHeader />
<main class="m-container mx-auto max-w-5xl">
<transition name="fade" mode="out-in">
<div :key="getKeyForRoute()">
<NuxtPage />
</div>
</transition>
</main>
<AppFooter />
</div>
</NuxtLayout>
<div>
<NuxtLayout>
<div class="text-gray-700">
<div class="fg"></div>
<AppHeader />
<main class="m-container mx-auto max-w-5xl">
<transition name="fade" mode="out-in">
<div :key="getKeyForRoute()">
<NuxtPage />
</div>
</transition>
</main>
<AppFooter />
</div>
</NuxtLayout>
</div>
</template>

<script setup lang="ts">
Expand Down
19 changes: 17 additions & 2 deletions src/components/AppHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
py-2
md:py-3
">
<NuxtLink :to="localePath('/')" :aria-label="t('Core.Header.Logo')">
<NuxtLink @click="navTo('/')" :aria-label="t('Core.Header.Logo')">
<img src="/images/logo.png" width="96" height="auto" :alt="t('Core.Header.Logo')" />
</NuxtLink>
<div class="-mr-2 -my-2 md:hidden">
Expand Down Expand Up @@ -84,7 +84,8 @@
</li>
<ol class="rounded bg-white p-2 mt-2" v-show="menuLocaleOpened">
<li v-for="locale in getLocales()" :key="locale.code">
<nuxt-link :to="switchLocalePath(locale.code)" class="flex items-center hover:text-blue-600 text-blue-800">
<nuxt-link :to="switchLocalePath(locale.code)" @click="clearError"
class="flex items-center hover:text-blue-600 text-blue-800">
<div class="rounded-sm drop-shadow mr-2 locale" :class="'locale-' + locale.code"></div>
{{ locale.name }}
</nuxt-link>
Expand All @@ -105,6 +106,10 @@ export interface ILocale {
name: string;
}
const props = defineProps({
shouldClearError: Boolean
});
const { t, locales, locale, localeProperties } = useI18n();
const switchLocalePath = useSwitchLocalePath();
const localePath = useLocalePath();
Expand All @@ -113,9 +118,19 @@ const initialized = ref(false);
const menuOpened = ref(false);
const menuHeight = ref("0px");
const menuLocaleOpened = ref(false);
const router = useRouter();
onMounted(() => (initialized.value = true));
const navTo = (basePath: string) => {
const path = localePath(basePath);
if (props.shouldClearError) {
clearError({ redirect: path });
} else {
router.replace(path);
}
}
const getCurrentLocale = () => {
return {
code: locale.value,
Expand Down
6 changes: 4 additions & 2 deletions src/components/Error.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
{{ t("Errors." + errLocale + ".Description") }}
<slot />
</div>
<NuxtLink :to="localePath('/')" class="
<NuxtLink :to="localePath('/')" @click="clearError" class="
uppercase
block
text-center text-sky-300
Expand All @@ -26,10 +26,12 @@
</template>

<script setup lang="ts">
import type { NuxtError } from "#app";
const { t } = useI18n();
const localePath = useLocalePath();
const props = defineProps({
error: Object
error: Object as () => NuxtError
});
const route = useRoute();
Expand Down
30 changes: 17 additions & 13 deletions src/error.vue
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
<template>
<NuxtLayout>
<div class="text-gray-700">
<div class="fg"></div>
<AppHeader />
<main class="m-container mx-auto max-w-5xl">
<transition name="fade" mode="out-in">
<Error :error="error" />
</transition>
</main>
<AppFooter />
</div>
</NuxtLayout>
<div>
<NuxtLayout>
<div class="text-gray-700">
<div class="fg"></div>
<AppHeader />
<main class="m-container mx-auto max-w-5xl">
<transition name="fade" mode="out-in">
<Error :error="error" />
</transition>
</main>
<AppFooter />
</div>
</NuxtLayout>
</div>
</template>

<script lang="ts" setup>
import type { NuxtError } from "#app";
const props = defineProps({
error: Object
error: Object as () => NuxtError
});
</script>

0 comments on commit 7413897

Please sign in to comment.