From a5346e86227d64f6fa154eb259c82e3d6c6cea01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=98=99=E2=97=A6=20The=20Tablet=20=E2=9D=80=20GamerGirla?= =?UTF-8?q?ndCo=20=E2=97=A6=E2=9D=A7?= Date: Sat, 9 Dec 2023 17:12:46 -0500 Subject: [PATCH] fix(client-side): add error check to story redirect middleware --- lib/client/middleware.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/client/middleware.ts b/lib/client/middleware.ts index ec32a45..bca7374 100644 --- a/lib/client/middleware.ts +++ b/lib/client/middleware.ts @@ -1,4 +1,7 @@ import { SingleChapterResult } from "./types/slightlyDifferentStory"; +import { IChapter } from "~/models/stories/chapter"; +import { IStory } from "~/models/stories"; +import { messages } from "~/lib/server/constants"; export const storyMiddleware = defineNuxtRouteMiddleware(async (to, from) => { const { getSession } = useAuth(); @@ -8,6 +11,11 @@ export const storyMiddleware = defineNuxtRouteMiddleware(async (to, from) => { const { data: story, error } = await useApiFetch( to.path, ); + if (error.value) { + return showError(error.value); + } else if (!story.value) { + return showError({ statusCode: 404, message: messages[404] }); + } console.log("fns", story, error); if (!data?.value?.user && story.value?.currentChapter.loggedInOnly) { return navigateTo("/login");