fix: handle missing Komga configuration gracefully by returning an empty array instead of an error in API routes
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user