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 { KomgaBookWithPages } from "@/types/komga";
import { ErrorMessage } from "@/components/ui/ErrorMessage"; import { ErrorMessage } from "@/components/ui/ErrorMessage";
import { ERROR_CODES } from "@/constants/errorCodes"; import { ERROR_CODES } from "@/constants/errorCodes";
import { AppError } from "@/utils/errors";
async function BookPage({ params }: { params: { bookId: string } }) { async function BookPage({ params }: { params: { bookId: string } }) {
try { try {
@@ -19,6 +20,13 @@ async function BookPage({ params }: { params: { bookId: string } }) {
); );
} catch (error) { } catch (error) {
console.error("Erreur:", error); console.error("Erreur:", error);
if (error instanceof AppError) {
return (
<div className="container py-8 space-y-8">
<ErrorMessage errorCode={error.code} />
</div>
);
}
return ( return (
<div className="container py-8 space-y-8"> <div className="container py-8 space-y-8">
<ErrorMessage errorCode={ERROR_CODES.SERIES.FETCH_ERROR} /> <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 { KomgaSeries, KomgaLibrary } from "@/types/komga";
import { UserPreferences } from "@/types/preferences"; import { UserPreferences } from "@/types/preferences";
import { ERROR_CODES } from "@/constants/errorCodes"; import { ERROR_CODES } from "@/constants/errorCodes";
import { AppError } from "@/utils/errors";
interface PageProps { interface PageProps {
params: { libraryId: string }; params: { libraryId: string };
@@ -51,7 +52,7 @@ async function getLibrarySeries(
return { data: series, library }; return { data: series, library };
} catch (error) { } 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> </div>
); );
} catch (error) { } catch (error) {
if (error instanceof Error) { if (error instanceof AppError) {
return ( return (
<div className="container py-8 space-y-8"> <div className="container py-8 space-y-8">
<div className="flex items-center justify-between"> <div className="flex items-center justify-between">
<h1 className="text-3xl font-bold">Séries</h1> <h1 className="text-3xl font-bold">Séries</h1>
<RefreshButton libraryId={params.libraryId} refreshLibrary={refreshLibrary} /> <RefreshButton libraryId={params.libraryId} refreshLibrary={refreshLibrary} />
</div> </div>
<ErrorMessage errorCode={ERROR_CODES.SERIES.FETCH_ERROR} /> <ErrorMessage errorCode={error.code} />
</div> </div>
); );
} }

View File

@@ -30,6 +30,13 @@ async function HomePage() {
if (error instanceof AppError && error.code === ERROR_CODES.KOMGA.MISSING_CONFIG) { if (error instanceof AppError && error.code === ERROR_CODES.KOMGA.MISSING_CONFIG) {
redirect("/settings"); redirect("/settings");
} }
if (error instanceof AppError) {
return (
<main className="container mx-auto px-4 py-8">
<ErrorMessage errorCode={error.code} />
</main>
);
}
return ( return (
<main className="container mx-auto px-4 py-8"> <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 { KomgaBook, KomgaSeries } from "@/types/komga";
import { UserPreferences } from "@/types/preferences"; import { UserPreferences } from "@/types/preferences";
import { ERROR_CODES } from "@/constants/errorCodes"; import { ERROR_CODES } from "@/constants/errorCodes";
import { AppError } from "@/utils/errors";
interface PageProps { interface PageProps {
params: { seriesId: string }; params: { seriesId: string };
@@ -76,6 +77,13 @@ async function SeriesPage({ params, searchParams }: PageProps) {
</div> </div>
); );
} catch (error) { } catch (error) {
if (error instanceof AppError) {
return (
<div className="container py-8 space-y-8">
<ErrorMessage errorCode={error.code} />
</div>
);
}
return ( return (
<div className="container py-8 space-y-8"> <div className="container py-8 space-y-8">
<h1 className="text-3xl font-bold">Série</h1> <h1 className="text-3xl font-bold">Série</h1>

View File

@@ -6,6 +6,7 @@ import { authService } from "@/lib/services/auth.service";
import { AppErrorType } from "@/types/global"; import { AppErrorType } from "@/types/global";
import { ErrorMessage } from "@/components/ui/ErrorMessage"; import { ErrorMessage } from "@/components/ui/ErrorMessage";
import { useTranslate } from "@/hooks/useTranslate"; import { useTranslate } from "@/hooks/useTranslate";
import { AppError } from "@/utils/errors";
interface LoginFormProps { interface LoginFormProps {
from?: string; from?: string;
@@ -89,7 +90,7 @@ export function LoginForm({ from }: LoginFormProps) {
{t("login.form.remember")} {t("login.form.remember")}
</label> </label>
</div> </div>
{error && <ErrorMessage errorCode={error.code} variant="form" />} {error && error instanceof AppError && <ErrorMessage errorCode={error.code} variant="form" />}
<button <button
type="submit" type="submit"
disabled={isLoading} disabled={isLoading}

View File

@@ -8,6 +8,7 @@ import { ERROR_CODES } from "@/constants/errorCodes";
import { ErrorMessage } from "@/components/ui/ErrorMessage"; import { ErrorMessage } from "@/components/ui/ErrorMessage";
import { useTranslate } from "@/hooks/useTranslate"; import { useTranslate } from "@/hooks/useTranslate";
import { getErrorMessage } from "@/utils/errors"; import { getErrorMessage } from "@/utils/errors";
import { AppError } from "@/utils/errors";
interface RegisterFormProps { interface RegisterFormProps {
from?: string; from?: string;
@@ -100,7 +101,7 @@ export function RegisterForm({ from }: RegisterFormProps) {
className="flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50" className="flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50"
/> />
</div> </div>
{error && <ErrorMessage errorCode={error.code} variant="form" />} {error && error instanceof AppError && <ErrorMessage errorCode={error.code} variant="form" />}
<button <button
type="submit" type="submit"
disabled={isLoading} disabled={isLoading}

View File

@@ -43,7 +43,7 @@ export const ErrorMessage = ({ errorCode, error, variant = "default" }: ErrorMes
<div className="flex-1"> <div className="flex-1">
<h3 className="mb-1 font-medium text-destructive dark:text-red-400"> <h3 className="mb-1 font-medium text-destructive dark:text-red-400">
Une erreur est survenue {t("errors.GENERIC_ERROR")}
</h3> </h3>
<p className="text-sm text-destructive/90 dark:text-red-300/90">{message}</p> <p className="text-sm text-destructive/90 dark:text-red-300/90">{message}</p>
</div> </div>

View File

@@ -259,6 +259,8 @@
"SERIES_FETCH_ERROR": "Error fetching series", "SERIES_FETCH_ERROR": "Error fetching series",
"HOME_FETCH_ERROR": "Error fetching home", "HOME_FETCH_ERROR": "Error fetching home",
"SERIES_NO_BOOKS_FOUND": "No books found in the series" "SERIES_NO_BOOKS_FOUND": "No books found in the series",
"GENERIC_ERROR": "An error occurred"
} }
} }

View File

@@ -259,6 +259,8 @@
"SERIES_FETCH_ERROR": "Erreur lors de la récupération des séries", "SERIES_FETCH_ERROR": "Erreur lors de la récupération des séries",
"HOME_FETCH_ERROR": "Erreur lors de la récupération de l'accueil", "HOME_FETCH_ERROR": "Erreur lors de la récupération de l'accueil",
"SERIES_NO_BOOKS_FOUND": "Aucun livre trouvé dans la série" "SERIES_NO_BOOKS_FOUND": "Aucun livre trouvé dans la série",
"GENERIC_ERROR": "Une erreur est survenue"
} }
} }