fix: errorMessage has to throw apperror code if apperror

This commit is contained in:
Julien Froidefond
2025-02-28 08:00:34 +01:00
parent 5893f1a15f
commit bc2ceadb8f
9 changed files with 38 additions and 8 deletions

View File

@@ -7,6 +7,7 @@ import { withPageTiming } from "@/lib/hoc/withPageTiming";
import { KomgaBookWithPages } from "@/types/komga";
import { ErrorMessage } from "@/components/ui/ErrorMessage";
import { ERROR_CODES } from "@/constants/errorCodes";
import { AppError } from "@/utils/errors";
async function BookPage({ params }: { params: { bookId: string } }) {
try {
@@ -19,6 +20,13 @@ async function BookPage({ params }: { params: { bookId: string } }) {
);
} catch (error) {
console.error("Erreur:", error);
if (error instanceof AppError) {
return (
<div className="container py-8 space-y-8">
<ErrorMessage errorCode={error.code} />
</div>
);
}
return (
<div className="container py-8 space-y-8">
<ErrorMessage errorCode={ERROR_CODES.SERIES.FETCH_ERROR} />

View File

@@ -9,6 +9,7 @@ import { LibraryResponse } from "@/types/library";
import { KomgaSeries, KomgaLibrary } from "@/types/komga";
import { UserPreferences } from "@/types/preferences";
import { ERROR_CODES } from "@/constants/errorCodes";
import { AppError } from "@/utils/errors";
interface PageProps {
params: { libraryId: string };
@@ -51,7 +52,7 @@ async function getLibrarySeries(
return { data: series, library };
} catch (error) {
throw error instanceof Error ? error : new Error("Erreur lors de la récupération des séries");
throw error instanceof Error ? error : new AppError(ERROR_CODES.SERIES.FETCH_ERROR, {}, error);
}
}
@@ -92,14 +93,14 @@ async function LibraryPage({ params, searchParams }: PageProps) {
</div>
);
} catch (error) {
if (error instanceof Error) {
if (error instanceof AppError) {
return (
<div className="container py-8 space-y-8">
<div className="flex items-center justify-between">
<h1 className="text-3xl font-bold">Séries</h1>
<RefreshButton libraryId={params.libraryId} refreshLibrary={refreshLibrary} />
</div>
<ErrorMessage errorCode={ERROR_CODES.SERIES.FETCH_ERROR} />
<ErrorMessage errorCode={error.code} />
</div>
);
}

View File

@@ -30,6 +30,13 @@ async function HomePage() {
if (error instanceof AppError && error.code === ERROR_CODES.KOMGA.MISSING_CONFIG) {
redirect("/settings");
}
if (error instanceof AppError) {
return (
<main className="container mx-auto px-4 py-8">
<ErrorMessage errorCode={error.code} />
</main>
);
}
return (
<main className="container mx-auto px-4 py-8">

View File

@@ -9,6 +9,7 @@ import { LibraryResponse } from "@/types/library";
import { KomgaBook, KomgaSeries } from "@/types/komga";
import { UserPreferences } from "@/types/preferences";
import { ERROR_CODES } from "@/constants/errorCodes";
import { AppError } from "@/utils/errors";
interface PageProps {
params: { seriesId: string };
@@ -76,6 +77,13 @@ async function SeriesPage({ params, searchParams }: PageProps) {
</div>
);
} catch (error) {
if (error instanceof AppError) {
return (
<div className="container py-8 space-y-8">
<ErrorMessage errorCode={error.code} />
</div>
);
}
return (
<div className="container py-8 space-y-8">
<h1 className="text-3xl font-bold">Série</h1>