From 4994cbd2e92d0f2634de3efbbc5fbb17402608a0 Mon Sep 17 00:00:00 2001 From: Julien Froidefond Date: Thu, 27 Feb 2025 22:13:53 +0100 Subject: [PATCH] refacto : error detection in home and fallback in books/id --- src/app/books/[bookId]/page.tsx | 7 ++++++- src/app/page.tsx | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/app/books/[bookId]/page.tsx b/src/app/books/[bookId]/page.tsx index ca99378..e927795 100644 --- a/src/app/books/[bookId]/page.tsx +++ b/src/app/books/[bookId]/page.tsx @@ -5,6 +5,7 @@ import { BookService } from "@/lib/services/book.service"; import { notFound } from "next/navigation"; import { withPageTiming } from "@/lib/hoc/withPageTiming"; import { KomgaBookWithPages } from "@/types/komga"; +import { ErrorMessage } from "@/components/ui/ErrorMessage"; async function BookPage({ params }: { params: { bookId: string } }) { try { @@ -17,7 +18,11 @@ async function BookPage({ params }: { params: { bookId: string } }) { ); } catch (error) { console.error("Erreur:", error); - notFound(); + return ( +
+ +
+ ); } } diff --git a/src/app/page.tsx b/src/app/page.tsx index 028737b..8b6fc06 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -4,7 +4,9 @@ import { redirect } from "next/navigation"; import { revalidatePath } from "next/cache"; import { withPageTiming } from "@/lib/hoc/withPageTiming"; import { ErrorMessage } from "@/components/ui/ErrorMessage"; +import { ERROR_CODES } from "@/constants/errorCodes"; import { HomeData } from "@/lib/services/home.service"; +import { AppError } from "@/utils/errors"; async function refreshHome() { "use server"; @@ -26,7 +28,7 @@ async function HomePage() { return ; } catch (error) { // Si l'erreur indique une configuration manquante, rediriger vers les préférences - if (error instanceof Error && error.message.includes("Configuration Komga non trouvée")) { + if (error instanceof AppError && error.code === ERROR_CODES.KOMGA.MISSING_CONFIG) { redirect("/settings"); }