refacto : error detection in home and fallback in books/id
This commit is contained in:
@@ -5,6 +5,7 @@ import { BookService } from "@/lib/services/book.service";
|
|||||||
import { notFound } from "next/navigation";
|
import { notFound } from "next/navigation";
|
||||||
import { withPageTiming } from "@/lib/hoc/withPageTiming";
|
import { withPageTiming } from "@/lib/hoc/withPageTiming";
|
||||||
import { KomgaBookWithPages } from "@/types/komga";
|
import { KomgaBookWithPages } from "@/types/komga";
|
||||||
|
import { ErrorMessage } from "@/components/ui/ErrorMessage";
|
||||||
|
|
||||||
async function BookPage({ params }: { params: { bookId: string } }) {
|
async function BookPage({ params }: { params: { bookId: string } }) {
|
||||||
try {
|
try {
|
||||||
@@ -17,7 +18,11 @@ async function BookPage({ params }: { params: { bookId: string } }) {
|
|||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Erreur:", error);
|
console.error("Erreur:", error);
|
||||||
notFound();
|
return (
|
||||||
|
<div className="container py-8 space-y-8">
|
||||||
|
<ErrorMessage error={error as Error} errorCode="BOOK_FETCH_ERROR" />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,9 @@ import { redirect } from "next/navigation";
|
|||||||
import { revalidatePath } from "next/cache";
|
import { revalidatePath } from "next/cache";
|
||||||
import { withPageTiming } from "@/lib/hoc/withPageTiming";
|
import { withPageTiming } from "@/lib/hoc/withPageTiming";
|
||||||
import { ErrorMessage } from "@/components/ui/ErrorMessage";
|
import { ErrorMessage } from "@/components/ui/ErrorMessage";
|
||||||
|
import { ERROR_CODES } from "@/constants/errorCodes";
|
||||||
import { HomeData } from "@/lib/services/home.service";
|
import { HomeData } from "@/lib/services/home.service";
|
||||||
|
import { AppError } from "@/utils/errors";
|
||||||
|
|
||||||
async function refreshHome() {
|
async function refreshHome() {
|
||||||
"use server";
|
"use server";
|
||||||
@@ -26,7 +28,7 @@ async function HomePage() {
|
|||||||
return <HomeContent data={data} refreshHome={refreshHome} />;
|
return <HomeContent data={data} refreshHome={refreshHome} />;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Si l'erreur indique une configuration manquante, rediriger vers les préférences
|
// 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");
|
redirect("/settings");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user