refactor: simplify HomePage and LibraryPage components by integrating ClientHomePage and ClientLibraryPage, enhancing data fetching and error handling

This commit is contained in:
Julien Froidefond
2025-10-17 08:46:19 +02:00
parent bf94c29bc6
commit e396503ddb
9 changed files with 523 additions and 242 deletions

View File

@@ -0,0 +1,38 @@
import { NextResponse } from "next/server";
import { HomeService } from "@/lib/services/home.service";
import { ERROR_CODES } from "@/constants/errorCodes";
import { AppError } from "@/utils/errors";
import { getErrorMessage } from "@/utils/errors";
export const dynamic = "force-dynamic";
export async function GET() {
try {
const data = await HomeService.getHomeData();
return NextResponse.json(data);
} catch (error) {
console.error("API Home - Erreur:", error);
if (error instanceof AppError) {
return NextResponse.json(
{
error: {
code: error.code,
name: "Home data fetch error",
message: getErrorMessage(error.code),
},
},
{ status: error.code === ERROR_CODES.KOMGA.MISSING_CONFIG ? 404 : 500 }
);
}
return NextResponse.json(
{
error: {
code: ERROR_CODES.KOMGA.SERVER_UNREACHABLE,
name: "Home data fetch error",
message: getErrorMessage(ERROR_CODES.KOMGA.SERVER_UNREACHABLE),
},
},
{ status: 500 }
);
}
}