refacto: errors in apis
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { AuthServerService } from "@/lib/services/auth-server.service";
|
||||
import { ERROR_CODES } from "@/constants/errorCodes";
|
||||
import { ERROR_MESSAGES } from "@/constants/errorMessages";
|
||||
import { AppError } from "@/utils/errors";
|
||||
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
@@ -9,14 +12,17 @@ export async function POST(request: Request) {
|
||||
const userData = await AuthServerService.loginUser(email, password);
|
||||
AuthServerService.setUserCookie(userData);
|
||||
|
||||
return NextResponse.json({ message: "Connexion réussie", user: userData });
|
||||
return NextResponse.json({
|
||||
message: "✅ Connexion réussie",
|
||||
user: userData,
|
||||
});
|
||||
} catch (error) {
|
||||
if (error instanceof Error && error.message === "INVALID_CREDENTIALS") {
|
||||
if (error instanceof AppError) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: {
|
||||
code: "INVALID_CREDENTIALS",
|
||||
message: "Email ou mot de passe incorrect",
|
||||
code: error.code,
|
||||
message: ERROR_MESSAGES[error.code],
|
||||
},
|
||||
},
|
||||
{ status: 401 }
|
||||
@@ -29,8 +35,8 @@ export async function POST(request: Request) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: {
|
||||
code: "SERVER_ERROR",
|
||||
message: "Une erreur est survenue lors de la connexion",
|
||||
code: ERROR_CODES.AUTH.INVALID_CREDENTIALS,
|
||||
message: ERROR_MESSAGES[ERROR_CODES.AUTH.INVALID_CREDENTIALS],
|
||||
},
|
||||
},
|
||||
{ status: 500 }
|
||||
|
||||
@@ -1,9 +1,23 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { cookies } from "next/headers";
|
||||
import { ERROR_CODES } from "@/constants/errorCodes";
|
||||
import { ERROR_MESSAGES } from "@/constants/errorMessages";
|
||||
|
||||
export async function POST() {
|
||||
// Supprimer le cookie
|
||||
cookies().delete("stripUser");
|
||||
|
||||
return NextResponse.json({ message: "Déconnexion réussie" });
|
||||
try {
|
||||
// Supprimer le cookie
|
||||
cookies().delete("stripUser");
|
||||
return NextResponse.json({ message: "👋 Déconnexion réussie" });
|
||||
} catch (error) {
|
||||
console.error("Erreur lors de la déconnexion:", error);
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: {
|
||||
code: ERROR_CODES.AUTH.LOGOUT_ERROR,
|
||||
message: ERROR_MESSAGES[ERROR_CODES.AUTH.LOGOUT_ERROR],
|
||||
},
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { AuthServerService } from "@/lib/services/auth-server.service";
|
||||
import { ERROR_CODES } from "@/constants/errorCodes";
|
||||
import { ERROR_MESSAGES } from "@/constants/errorMessages";
|
||||
import { AppError } from "@/utils/errors";
|
||||
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
@@ -9,28 +12,25 @@ export async function POST(request: Request) {
|
||||
const userData = await AuthServerService.createUser(email, password);
|
||||
AuthServerService.setUserCookie(userData);
|
||||
|
||||
return NextResponse.json({ message: "Inscription réussie", user: userData });
|
||||
return NextResponse.json({
|
||||
message: "✅ Inscription réussie",
|
||||
user: userData,
|
||||
});
|
||||
} catch (error) {
|
||||
if (error instanceof Error && error.message === "EMAIL_EXISTS") {
|
||||
if (error instanceof AppError) {
|
||||
const status =
|
||||
error.code === ERROR_CODES.AUTH.EMAIL_EXISTS ||
|
||||
error.code === ERROR_CODES.AUTH.PASSWORD_NOT_STRONG
|
||||
? 400
|
||||
: 500;
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: {
|
||||
code: "EMAIL_EXISTS",
|
||||
message: "Cet email est déjà utilisé",
|
||||
code: error.code,
|
||||
message: ERROR_MESSAGES[error.code],
|
||||
},
|
||||
},
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
if (error instanceof Error && error.message === "PASSWORD_NOT_STRONG") {
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: {
|
||||
code: "PASSWORD_NOT_STRONG",
|
||||
message: "Le mot de passe est trop faible",
|
||||
},
|
||||
},
|
||||
{ status: 400 }
|
||||
{ status }
|
||||
);
|
||||
}
|
||||
throw error;
|
||||
@@ -40,8 +40,8 @@ export async function POST(request: Request) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: {
|
||||
code: "SERVER_ERROR",
|
||||
message: "Une erreur est survenue lors de l'inscription",
|
||||
code: ERROR_CODES.AUTH.INVALID_USER_DATA,
|
||||
message: ERROR_MESSAGES[ERROR_CODES.AUTH.INVALID_USER_DATA],
|
||||
},
|
||||
},
|
||||
{ status: 500 }
|
||||
|
||||
@@ -1,12 +1,35 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { DebugService } from "@/lib/services/debug.service";
|
||||
import { ERROR_CODES } from "@/constants/errorCodes";
|
||||
import { ERROR_MESSAGES } from "@/constants/errorMessages";
|
||||
import { AppError } from "@/utils/errors";
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
const logs = await DebugService.getRequestLogs();
|
||||
return NextResponse.json(logs);
|
||||
} catch (error) {
|
||||
return NextResponse.json({ error: "Erreur lors de la récupération des logs" }, { status: 500 });
|
||||
console.error("Erreur lors de la récupération des logs:", error);
|
||||
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.DEBUG.FETCH_ERROR,
|
||||
message: ERROR_MESSAGES[ERROR_CODES.DEBUG.FETCH_ERROR],
|
||||
},
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,17 +37,61 @@ export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const timing = await request.json();
|
||||
await DebugService.logRequest(timing);
|
||||
return NextResponse.json({ success: true });
|
||||
return NextResponse.json({
|
||||
message: "✅ Log enregistré avec succès",
|
||||
});
|
||||
} catch (error) {
|
||||
return NextResponse.json({ error: "Erreur lors de l'enregistrement du log" }, { status: 500 });
|
||||
console.error("Erreur lors de l'enregistrement du log:", error);
|
||||
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.DEBUG.SAVE_ERROR,
|
||||
message: ERROR_MESSAGES[ERROR_CODES.DEBUG.SAVE_ERROR],
|
||||
},
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export async function DELETE() {
|
||||
try {
|
||||
await DebugService.clearLogs();
|
||||
return NextResponse.json({ success: true });
|
||||
return NextResponse.json({
|
||||
message: "🧹 Logs supprimés avec succès",
|
||||
});
|
||||
} catch (error) {
|
||||
return NextResponse.json({ error: "Erreur lors de la suppression des logs" }, { status: 500 });
|
||||
console.error("Erreur lors de la suppression des logs:", error);
|
||||
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.DEBUG.CLEAR_ERROR,
|
||||
message: ERROR_MESSAGES[ERROR_CODES.DEBUG.CLEAR_ERROR],
|
||||
},
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,30 @@
|
||||
import { NextResponse } from "next/server";
|
||||
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 const dynamic = "force-dynamic";
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
request: NextRequest,
|
||||
{ params }: { params: { bookId: string; pageNumber: string } }
|
||||
) {
|
||||
try {
|
||||
const response = await BookService.getPage(params.bookId, parseInt(params.pageNumber));
|
||||
const pageNumber = parseInt(params.pageNumber);
|
||||
if (isNaN(pageNumber) || pageNumber < 0) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: {
|
||||
code: ERROR_CODES.IMAGE.FETCH_ERROR,
|
||||
message: ERROR_MESSAGES[ERROR_CODES.IMAGE.FETCH_ERROR],
|
||||
},
|
||||
},
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
const response = await BookService.getPage(params.bookId, pageNumber);
|
||||
const buffer = await response.arrayBuffer();
|
||||
const headers = new Headers();
|
||||
headers.set("Content-Type", response.headers.get("Content-Type") || "image/jpeg");
|
||||
@@ -19,9 +35,25 @@ export async function GET(
|
||||
headers,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("API Book Page - Erreur:", error);
|
||||
console.error("Erreur lors de la récupération de la page:", error);
|
||||
if (error instanceof AppError) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: {
|
||||
code: error.code,
|
||||
message: ERROR_MESSAGES[error.code],
|
||||
},
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
return NextResponse.json(
|
||||
{ error: "Erreur lors de la récupération de la page" },
|
||||
{
|
||||
error: {
|
||||
code: ERROR_CODES.IMAGE.FETCH_ERROR,
|
||||
message: ERROR_MESSAGES[ERROR_CODES.IMAGE.FETCH_ERROR],
|
||||
},
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,35 +1,76 @@
|
||||
import { NextResponse } from "next/server";
|
||||
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 PATCH(request: Request, { params }: { params: { bookId: string } }) {
|
||||
export async function PATCH(request: NextRequest, { params }: { params: { bookId: string } }) {
|
||||
try {
|
||||
const { page, completed } = await request.json();
|
||||
|
||||
if (typeof page !== "number") {
|
||||
return NextResponse.json(
|
||||
{ error: "Le numéro de page est requis et doit être un nombre" },
|
||||
{
|
||||
error: {
|
||||
code: ERROR_CODES.BOOK.PROGRESS_UPDATE_ERROR,
|
||||
message: ERROR_MESSAGES[ERROR_CODES.BOOK.PROGRESS_UPDATE_ERROR],
|
||||
},
|
||||
},
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
await BookService.updateReadProgress(params.bookId, page, completed);
|
||||
return NextResponse.json({ message: "Progression mise à jour avec succès" });
|
||||
return NextResponse.json({ message: "📖 Progression mise à jour avec succès" });
|
||||
} catch (error) {
|
||||
console.error("API Read Progress - Erreur:", error);
|
||||
console.error("Erreur lors de la mise à jour de la progression:", error);
|
||||
if (error instanceof AppError) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: {
|
||||
code: error.code,
|
||||
message: ERROR_MESSAGES[error.code],
|
||||
},
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
return NextResponse.json(
|
||||
{ error: "Erreur lors de la mise à jour de la progression" },
|
||||
{
|
||||
error: {
|
||||
code: ERROR_CODES.BOOK.PROGRESS_UPDATE_ERROR,
|
||||
message: ERROR_MESSAGES[ERROR_CODES.BOOK.PROGRESS_UPDATE_ERROR],
|
||||
},
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
export async function DELETE(request: Request, { params }: { params: { bookId: string } }) {
|
||||
|
||||
export async function DELETE(request: NextRequest, { params }: { params: { bookId: string } }) {
|
||||
try {
|
||||
await BookService.deleteReadProgress(params.bookId);
|
||||
return NextResponse.json({ message: "Progression supprimée avec succès" });
|
||||
return NextResponse.json({ message: "🗑️ Progression supprimée avec succès" });
|
||||
} catch (error) {
|
||||
console.error("API Delete Read Progress - Erreur:", error);
|
||||
console.error("Erreur lors de la suppression de la progression:", error);
|
||||
if (error instanceof AppError) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: {
|
||||
code: error.code,
|
||||
message: ERROR_MESSAGES[error.code],
|
||||
},
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
return NextResponse.json(
|
||||
{ error: "Erreur lors de la suppression de la progression" },
|
||||
{
|
||||
error: {
|
||||
code: ERROR_CODES.BOOK.PROGRESS_DELETE_ERROR,
|
||||
message: ERROR_MESSAGES[ERROR_CODES.BOOK.PROGRESS_DELETE_ERROR],
|
||||
},
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import { 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: Request, { params }: { params: { bookId: string } }) {
|
||||
try {
|
||||
@@ -7,6 +10,25 @@ export async function GET(request: Request, { params }: { params: { bookId: stri
|
||||
return NextResponse.json(data);
|
||||
} catch (error) {
|
||||
console.error("API Books - Erreur:", error);
|
||||
return NextResponse.json({ error: "Erreur lors de la récupération du tome" }, { 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.BOOK.NOT_FOUND,
|
||||
message: ERROR_MESSAGES[ERROR_CODES.BOOK.NOT_FOUND],
|
||||
},
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
21
src/app/api/komga/cache/clear/route.ts
vendored
21
src/app/api/komga/cache/clear/route.ts
vendored
@@ -1,8 +1,23 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { getServerCacheService } from "@/lib/services/server-cache.service";
|
||||
import { ERROR_CODES } from "@/constants/errorCodes";
|
||||
import { ERROR_MESSAGES } from "@/constants/errorMessages";
|
||||
|
||||
export async function POST() {
|
||||
const cacheService = await getServerCacheService();
|
||||
cacheService.clear();
|
||||
return NextResponse.json({ message: "Cache cleared" });
|
||||
try {
|
||||
const cacheService = await getServerCacheService();
|
||||
cacheService.clear();
|
||||
return NextResponse.json({ message: "🧹 Cache vidé avec succès" });
|
||||
} catch (error) {
|
||||
console.error("Erreur lors de la suppression du cache:", error);
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: {
|
||||
code: ERROR_CODES.CACHE.CLEAR_ERROR,
|
||||
message: ERROR_MESSAGES[ERROR_CODES.CACHE.CLEAR_ERROR],
|
||||
},
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
36
src/app/api/komga/cache/mode/route.ts
vendored
36
src/app/api/komga/cache/mode/route.ts
vendored
@@ -1,9 +1,24 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { getServerCacheService } from "@/lib/services/server-cache.service";
|
||||
import { ERROR_CODES } from "@/constants/errorCodes";
|
||||
import { ERROR_MESSAGES } from "@/constants/errorMessages";
|
||||
|
||||
export async function GET() {
|
||||
const cacheService = await getServerCacheService();
|
||||
return NextResponse.json({ mode: cacheService.getCacheMode() });
|
||||
try {
|
||||
const cacheService = await getServerCacheService();
|
||||
return NextResponse.json({ mode: cacheService.getCacheMode() });
|
||||
} catch (error) {
|
||||
console.error("Erreur lors de la récupération du mode de cache:", error);
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: {
|
||||
code: ERROR_CODES.CACHE.MODE_FETCH_ERROR,
|
||||
message: ERROR_MESSAGES[ERROR_CODES.CACHE.MODE_FETCH_ERROR],
|
||||
},
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export async function POST(request: Request) {
|
||||
@@ -11,7 +26,12 @@ export async function POST(request: Request) {
|
||||
const { mode } = await request.json();
|
||||
if (mode !== "file" && mode !== "memory") {
|
||||
return NextResponse.json(
|
||||
{ error: "Invalid mode. Must be 'file' or 'memory'" },
|
||||
{
|
||||
error: {
|
||||
code: ERROR_CODES.CACHE.INVALID_MODE,
|
||||
message: ERROR_MESSAGES[ERROR_CODES.CACHE.INVALID_MODE],
|
||||
},
|
||||
},
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
@@ -21,6 +41,14 @@ export async function POST(request: Request) {
|
||||
return NextResponse.json({ mode: cacheService.getCacheMode() });
|
||||
} catch (error) {
|
||||
console.error("Erreur lors de la mise à jour du mode de cache:", error);
|
||||
return NextResponse.json({ error: "Invalid request" }, { status: 400 });
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: {
|
||||
code: ERROR_CODES.CACHE.MODE_UPDATE_ERROR,
|
||||
message: ERROR_MESSAGES[ERROR_CODES.CACHE.MODE_UPDATE_ERROR],
|
||||
},
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { ConfigDBService } from "@/lib/services/config-db.service";
|
||||
import { ERROR_CODES } from "@/constants/errorCodes";
|
||||
import { ERROR_MESSAGES } from "@/constants/errorMessages";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
@@ -15,16 +17,29 @@ export async function POST(request: Request) {
|
||||
userId: mongoConfig.userId,
|
||||
};
|
||||
return NextResponse.json(
|
||||
{ message: "Configuration sauvegardée avec succès", config },
|
||||
{ message: "⚙️ Configuration sauvegardée avec succès", config },
|
||||
{ status: 200 }
|
||||
);
|
||||
} catch (error) {
|
||||
console.error("Erreur lors de la sauvegarde de la configuration:", error);
|
||||
if (error instanceof Error && error.message === "Utilisateur non authentifié") {
|
||||
return NextResponse.json({ error: "Non autorisé" }, { status: 401 });
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: {
|
||||
code: ERROR_CODES.MIDDLEWARE.UNAUTHORIZED,
|
||||
message: ERROR_MESSAGES[ERROR_CODES.MIDDLEWARE.UNAUTHORIZED],
|
||||
},
|
||||
},
|
||||
{ status: 401 }
|
||||
);
|
||||
}
|
||||
return NextResponse.json(
|
||||
{ error: "Erreur lors de la sauvegarde de la configuration" },
|
||||
{
|
||||
error: {
|
||||
code: ERROR_CODES.CONFIG.SAVE_ERROR,
|
||||
message: ERROR_MESSAGES[ERROR_CODES.CONFIG.SAVE_ERROR],
|
||||
},
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
@@ -45,14 +60,35 @@ export async function GET() {
|
||||
console.error("Erreur lors de la récupération de la configuration:", error);
|
||||
if (error instanceof Error) {
|
||||
if (error.message === "Utilisateur non authentifié") {
|
||||
return NextResponse.json({ error: "Non autorisé" }, { status: 401 });
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: {
|
||||
code: ERROR_CODES.MIDDLEWARE.UNAUTHORIZED,
|
||||
message: ERROR_MESSAGES[ERROR_CODES.MIDDLEWARE.UNAUTHORIZED],
|
||||
},
|
||||
},
|
||||
{ status: 401 }
|
||||
);
|
||||
}
|
||||
if (error.message === "Configuration non trouvée") {
|
||||
return NextResponse.json({ error: "Configuration non trouvée" }, { status: 404 });
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: {
|
||||
code: ERROR_CODES.KOMGA.MISSING_CONFIG,
|
||||
message: ERROR_MESSAGES[ERROR_CODES.KOMGA.MISSING_CONFIG],
|
||||
},
|
||||
},
|
||||
{ status: 404 }
|
||||
);
|
||||
}
|
||||
}
|
||||
return NextResponse.json(
|
||||
{ error: "Erreur lors de la récupération de la configuration" },
|
||||
{
|
||||
error: {
|
||||
code: ERROR_CODES.CONFIG.FETCH_ERROR,
|
||||
message: ERROR_MESSAGES[ERROR_CODES.CONFIG.FETCH_ERROR],
|
||||
},
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { FavoriteService } from "@/lib/services/favorite.service";
|
||||
import { ERROR_CODES } from "@/constants/errorCodes";
|
||||
import { ERROR_MESSAGES } from "@/constants/errorMessages";
|
||||
import { AppError } from "@/utils/errors";
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
@@ -7,8 +10,24 @@ export async function GET() {
|
||||
return NextResponse.json(favoriteIds);
|
||||
} catch (error) {
|
||||
console.error("Erreur lors de la récupération des favoris:", error);
|
||||
if (error instanceof AppError) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: {
|
||||
code: error.code,
|
||||
message: ERROR_MESSAGES[error.code],
|
||||
},
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
return NextResponse.json(
|
||||
{ error: "Erreur lors de la récupération des favoris" },
|
||||
{
|
||||
error: {
|
||||
code: ERROR_CODES.FAVORITE.FETCH_ERROR,
|
||||
message: ERROR_MESSAGES[ERROR_CODES.FAVORITE.FETCH_ERROR],
|
||||
},
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
@@ -18,10 +37,29 @@ export async function POST(request: Request) {
|
||||
try {
|
||||
const { seriesId } = await request.json();
|
||||
await FavoriteService.addToFavorites(seriesId);
|
||||
return NextResponse.json({ message: "Favori ajouté avec succès" });
|
||||
return NextResponse.json({ message: "⭐️ Série ajoutée aux favoris" });
|
||||
} catch (error) {
|
||||
console.error("Erreur lors de l'ajout du favori:", error);
|
||||
return NextResponse.json({ error: "Erreur lors de l'ajout du favori" }, { 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.FAVORITE.ADD_ERROR,
|
||||
message: ERROR_MESSAGES[ERROR_CODES.FAVORITE.ADD_ERROR],
|
||||
},
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,9 +67,28 @@ export async function DELETE(request: Request) {
|
||||
try {
|
||||
const { seriesId } = await request.json();
|
||||
await FavoriteService.removeFromFavorites(seriesId);
|
||||
return NextResponse.json({ message: "Favori supprimé avec succès" });
|
||||
return NextResponse.json({ message: "💔 Série retirée des favoris" });
|
||||
} catch (error) {
|
||||
console.error("Erreur lors de la suppression du favori:", error);
|
||||
return NextResponse.json({ error: "Erreur lors de la suppression du favori" }, { 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.FAVORITE.DELETE_ERROR,
|
||||
message: ERROR_MESSAGES[ERROR_CODES.FAVORITE.DELETE_ERROR],
|
||||
},
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 const dynamic = "force-dynamic";
|
||||
|
||||
@@ -12,6 +15,25 @@ export async function GET(
|
||||
return response;
|
||||
} catch (error) {
|
||||
console.error("Erreur lors de la récupération de la page du livre:", error);
|
||||
return new NextResponse("Erreur lors de la récupération de la page", { 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 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +1,52 @@
|
||||
import { NextResponse } from "next/server";
|
||||
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 const dynamic = "force-dynamic";
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
request: NextRequest,
|
||||
{ params }: { params: { bookId: string; pageNumber: string } }
|
||||
) {
|
||||
try {
|
||||
// Convertir le numéro de page en nombre
|
||||
const pageNumber = parseInt(params.pageNumber);
|
||||
if (isNaN(pageNumber) || pageNumber < 0) {
|
||||
return NextResponse.json({ error: "Numéro de page invalide" }, { status: 400 });
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: {
|
||||
code: ERROR_CODES.BOOK.PAGES_FETCH_ERROR,
|
||||
message: ERROR_MESSAGES[ERROR_CODES.BOOK.PAGES_FETCH_ERROR],
|
||||
},
|
||||
},
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
const response = await BookService.getPageThumbnail(params.bookId, pageNumber);
|
||||
return response;
|
||||
} catch (error) {
|
||||
console.error("API Book Page Thumbnail - Erreur:", error);
|
||||
if (error instanceof Error) {
|
||||
return NextResponse.json({ error: error.message }, { status: 500 });
|
||||
console.error("Erreur lors de la récupération de la miniature de la page:", error);
|
||||
if (error instanceof AppError) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: {
|
||||
code: error.code,
|
||||
message: ERROR_MESSAGES[error.code],
|
||||
},
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
return NextResponse.json(
|
||||
{ error: "Une erreur est survenue lors de la récupération de la miniature" },
|
||||
{
|
||||
error: {
|
||||
code: ERROR_CODES.IMAGE.FETCH_ERROR,
|
||||
message: ERROR_MESSAGES[ERROR_CODES.IMAGE.FETCH_ERROR],
|
||||
},
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { SeriesService } from "@/lib/services/series.service";
|
||||
import { ERROR_CODES } from "@/constants/errorCodes";
|
||||
import { ERROR_MESSAGES } from "@/constants/errorMessages";
|
||||
import { AppError } from "@/utils/errors";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
@@ -9,6 +12,25 @@ export async function GET(request: NextRequest, { params }: { params: { seriesId
|
||||
return response;
|
||||
} catch (error) {
|
||||
console.error("Erreur lors de la récupération de la couverture de la série:", error);
|
||||
return new NextResponse("Erreur lors de la récupération de la couverture", { 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 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { SeriesService } from "@/lib/services/series.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: { seriesId: string } }) {
|
||||
try {
|
||||
@@ -7,6 +10,25 @@ export async function GET(request: NextRequest, { params }: { params: { seriesId
|
||||
return response;
|
||||
} catch (error) {
|
||||
console.error("Erreur lors de la récupération de la miniature de la série:", 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 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { LibraryService } from "@/lib/services/library.service";
|
||||
import { ERROR_CODES } from "@/constants/errorCodes";
|
||||
import { ERROR_MESSAGES } from "@/constants/errorMessages";
|
||||
import { AppError } from "@/utils/errors";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
@@ -9,6 +12,25 @@ export async function GET() {
|
||||
return NextResponse.json(libraries);
|
||||
} catch (error) {
|
||||
console.error("API Libraries - Erreur:", error);
|
||||
return NextResponse.json({ error: "Erreur serveur" }, { 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.LIBRARY.FETCH_ERROR,
|
||||
message: ERROR_MESSAGES[ERROR_CODES.LIBRARY.FETCH_ERROR],
|
||||
},
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { SeriesService } from "@/lib/services/series.service";
|
||||
import { ERROR_CODES } from "@/constants/errorCodes";
|
||||
import { ERROR_MESSAGES } from "@/constants/errorMessages";
|
||||
import { AppError } from "@/utils/errors";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
@@ -9,8 +12,24 @@ export async function GET(request: Request, { params }: { params: { seriesId: st
|
||||
return NextResponse.json(series);
|
||||
} catch (error) {
|
||||
console.error("API Series - Erreur:", error);
|
||||
if (error instanceof AppError) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: {
|
||||
code: error.code,
|
||||
message: ERROR_MESSAGES[error.code],
|
||||
},
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
return NextResponse.json(
|
||||
{ error: "Erreur lors de la récupération de la série" },
|
||||
{
|
||||
error: {
|
||||
code: ERROR_CODES.SERIES.FETCH_ERROR,
|
||||
message: ERROR_MESSAGES[ERROR_CODES.SERIES.FETCH_ERROR],
|
||||
},
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { TestService } from "@/lib/services/test.service";
|
||||
import { ERROR_CODES } from "@/constants/errorCodes";
|
||||
import { ERROR_MESSAGES } from "@/constants/errorMessages";
|
||||
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
@@ -12,14 +14,18 @@ export async function POST(request: Request) {
|
||||
});
|
||||
|
||||
return NextResponse.json({
|
||||
message: "Connexion réussie",
|
||||
librariesCount: libraries.length,
|
||||
message: `✅ Connexion réussie ! ${libraries.length} bibliothèque${
|
||||
libraries.length > 1 ? "s" : ""
|
||||
} trouvée${libraries.length > 1 ? "s" : ""}`,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Erreur lors du test de connexion:", error);
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: error instanceof Error ? error.message : "Erreur inconnue",
|
||||
error: {
|
||||
code: ERROR_CODES.KOMGA.CONNECTION_ERROR,
|
||||
message: ERROR_MESSAGES[ERROR_CODES.KOMGA.CONNECTION_ERROR],
|
||||
},
|
||||
},
|
||||
{ status: 400 }
|
||||
);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { ConfigDBService } from "@/lib/services/config-db.service";
|
||||
import { ERROR_CODES } from "@/constants/errorCodes";
|
||||
import { ERROR_MESSAGES } from "@/constants/errorMessages";
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
@@ -9,11 +11,24 @@ export async function GET() {
|
||||
console.error("Erreur lors de la récupération de la configuration TTL:", error);
|
||||
if (error instanceof Error) {
|
||||
if (error.message === "Utilisateur non authentifié") {
|
||||
return NextResponse.json({ error: "Non autorisé" }, { status: 401 });
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: {
|
||||
code: ERROR_CODES.MIDDLEWARE.UNAUTHORIZED,
|
||||
message: ERROR_MESSAGES[ERROR_CODES.MIDDLEWARE.UNAUTHORIZED],
|
||||
},
|
||||
},
|
||||
{ status: 401 }
|
||||
);
|
||||
}
|
||||
}
|
||||
return NextResponse.json(
|
||||
{ error: "Erreur lors de la récupération de la configuration TTL" },
|
||||
{
|
||||
error: {
|
||||
code: ERROR_CODES.CONFIG.TTL_FETCH_ERROR,
|
||||
message: ERROR_MESSAGES[ERROR_CODES.CONFIG.TTL_FETCH_ERROR],
|
||||
},
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
@@ -24,7 +39,7 @@ export async function POST(request: Request) {
|
||||
const data = await request.json();
|
||||
const config = await ConfigDBService.saveTTLConfig(data);
|
||||
return NextResponse.json({
|
||||
message: "Configuration TTL sauvegardée avec succès",
|
||||
message: "⏱️ Configuration TTL sauvegardée avec succès",
|
||||
config: {
|
||||
defaultTTL: config.defaultTTL,
|
||||
homeTTL: config.homeTTL,
|
||||
@@ -37,10 +52,23 @@ export async function POST(request: Request) {
|
||||
} catch (error) {
|
||||
console.error("Erreur lors de la sauvegarde de la configuration TTL:", error);
|
||||
if (error instanceof Error && error.message === "Utilisateur non authentifié") {
|
||||
return NextResponse.json({ error: "Non autorisé" }, { status: 401 });
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: {
|
||||
code: ERROR_CODES.MIDDLEWARE.UNAUTHORIZED,
|
||||
message: ERROR_MESSAGES[ERROR_CODES.MIDDLEWARE.UNAUTHORIZED],
|
||||
},
|
||||
},
|
||||
{ status: 401 }
|
||||
);
|
||||
}
|
||||
return NextResponse.json(
|
||||
{ error: "Erreur lors de la sauvegarde de la configuration TTL" },
|
||||
{
|
||||
error: {
|
||||
code: ERROR_CODES.CONFIG.TTL_SAVE_ERROR,
|
||||
message: ERROR_MESSAGES[ERROR_CODES.CONFIG.TTL_SAVE_ERROR],
|
||||
},
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { PreferencesService } from "@/lib/services/preferences.service";
|
||||
import { ERROR_CODES } from "@/constants/errorCodes";
|
||||
import { ERROR_MESSAGES } from "@/constants/errorMessages";
|
||||
import { AppError } from "@/utils/errors";
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
@@ -7,7 +10,26 @@ export async function GET() {
|
||||
return NextResponse.json(preferences);
|
||||
} catch (error) {
|
||||
console.error("Erreur lors de la récupération des préférences:", error);
|
||||
return new NextResponse("Erreur lors de la récupération des préférences", { 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.PREFERENCES.FETCH_ERROR,
|
||||
message: ERROR_MESSAGES[ERROR_CODES.PREFERENCES.FETCH_ERROR],
|
||||
},
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +40,25 @@ export async function PUT(request: NextRequest) {
|
||||
return NextResponse.json(updatedPreferences);
|
||||
} catch (error) {
|
||||
console.error("Erreur lors de la mise à jour des préférences:", error);
|
||||
return new NextResponse("Erreur lors de la mise à jour des préférences", { 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.PREFERENCES.UPDATE_ERROR,
|
||||
message: ERROR_MESSAGES[ERROR_CODES.PREFERENCES.UPDATE_ERROR],
|
||||
},
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user