fix: handle missing Komga configuration gracefully by returning an empty array instead of an error in API routes

This commit is contained in:
Julien Froidefond
2025-10-17 08:37:08 +02:00
parent b8af5e2468
commit bf94c29bc6
6 changed files with 418 additions and 784 deletions

View File

@@ -29,6 +29,12 @@ export async function GET() {
return NextResponse.json(validFavoriteIds);
} catch (error) {
if (error instanceof AppError) {
// Si la config Komga n'existe pas, retourner un tableau vide au lieu d'une erreur
if (error.code === ERROR_CODES.KOMGA.MISSING_CONFIG) {
return NextResponse.json([]);
}
}
console.error("Erreur lors de la récupération des favoris:", error);
if (error instanceof AppError) {
return NextResponse.json(

View File

@@ -11,6 +11,12 @@ export async function GET() {
const libraries: KomgaLibrary[] = await LibraryService.getLibraries();
return NextResponse.json(libraries);
} catch (error) {
if (error instanceof AppError) {
// Si la config Komga n'existe pas, retourner un tableau vide au lieu d'une erreur
if (error.code === ERROR_CODES.KOMGA.MISSING_CONFIG) {
return NextResponse.json([]);
}
}
console.error("API Libraries - Erreur:", error);
if (error instanceof AppError) {
return NextResponse.json(

View File

@@ -1,6 +1,7 @@
import { ReactElement } from "react";
import { DebugService } from "@/lib/services/debug.service";
type PageComponent = (props: any) => Promise<JSX.Element> | JSX.Element;
type PageComponent = (props: any) => Promise<ReactElement> | ReactElement;
export function withPageTiming(pageName: string, Component: PageComponent) {
return async function PageWithTiming(props: any) {

View File

@@ -33,6 +33,9 @@ export abstract class BaseApiService {
authHeader: config.authHeader,
};
} catch (error) {
if (error instanceof AppError && error.code === ERROR_CODES.KOMGA.MISSING_CONFIG) {
throw error;
}
console.error("Erreur lors de la récupération de la configuration:", error);
throw new AppError(ERROR_CODES.KOMGA.MISSING_CONFIG, {}, error);
}