refacto: errors in apis

This commit is contained in:
Julien Froidefond
2025-02-25 08:40:06 +01:00
parent bf6fa0a71d
commit a690a5af6f
29 changed files with 720 additions and 109 deletions

View File

@@ -1,5 +1,8 @@
import { NextRequest, NextResponse } from "next/server";
import { BookService } from "@/lib/services/book.service";
import { ERROR_CODES } from "@/constants/errorCodes";
import { ERROR_MESSAGES } from "@/constants/errorMessages";
import { AppError } from "@/utils/errors";
export async function GET(request: NextRequest, { params }: { params: { bookId: string } }) {
try {
@@ -7,6 +10,25 @@ export async function GET(request: NextRequest, { params }: { params: { bookId:
return response;
} catch (error) {
console.error("Erreur lors de la récupération de la miniature du livre:", error);
return new NextResponse("Erreur lors de la récupération de la miniature", { status: 500 });
if (error instanceof AppError) {
return NextResponse.json(
{
error: {
code: error.code,
message: ERROR_MESSAGES[error.code],
},
},
{ status: 500 }
);
}
return NextResponse.json(
{
error: {
code: ERROR_CODES.IMAGE.FETCH_ERROR,
message: ERROR_MESSAGES[ERROR_CODES.IMAGE.FETCH_ERROR],
},
},
{ status: 500 }
);
}
}