refacto: massive use of getMessageError

This commit is contained in:
Julien Froidefond
2025-02-27 14:26:48 +01:00
parent e76b849b17
commit 246c0c650a
26 changed files with 104 additions and 101 deletions

View File

@@ -1,7 +1,7 @@
import { NextResponse } from "next/server"; import { NextResponse } from "next/server";
import { AuthServerService } from "@/lib/services/auth-server.service"; import { AuthServerService } from "@/lib/services/auth-server.service";
import { ERROR_CODES } from "@/constants/errorCodes"; import { ERROR_CODES } from "@/constants/errorCodes";
import { ERROR_MESSAGES } from "@/constants/errorMessages"; import { getErrorMessage } from "@/utils/errors";
import { AppError } from "@/utils/errors"; import { AppError } from "@/utils/errors";
import { UserData } from "@/lib/services/auth-server.service"; import { UserData } from "@/lib/services/auth-server.service";
@@ -23,7 +23,7 @@ export async function POST(request: Request) {
{ {
error: { error: {
code: error.code, code: error.code,
message: ERROR_MESSAGES[error.code], message: getErrorMessage(error.code),
}, },
}, },
{ status: 401 } { status: 401 }
@@ -37,7 +37,7 @@ export async function POST(request: Request) {
{ {
error: { error: {
code: ERROR_CODES.AUTH.INVALID_CREDENTIALS, code: ERROR_CODES.AUTH.INVALID_CREDENTIALS,
message: ERROR_MESSAGES[ERROR_CODES.AUTH.INVALID_CREDENTIALS], message: getErrorMessage(ERROR_CODES.AUTH.INVALID_CREDENTIALS),
}, },
}, },
{ status: 500 } { status: 500 }

View File

@@ -1,7 +1,7 @@
import { NextResponse } from "next/server"; import { NextResponse } from "next/server";
import { cookies } from "next/headers"; import { cookies } from "next/headers";
import { ERROR_CODES } from "@/constants/errorCodes"; import { ERROR_CODES } from "@/constants/errorCodes";
import { ERROR_MESSAGES } from "@/constants/errorMessages"; import { getErrorMessage } from "@/utils/errors";
export async function POST() { export async function POST() {
try { try {
@@ -14,7 +14,7 @@ export async function POST() {
{ {
error: { error: {
code: ERROR_CODES.AUTH.LOGOUT_ERROR, code: ERROR_CODES.AUTH.LOGOUT_ERROR,
message: ERROR_MESSAGES[ERROR_CODES.AUTH.LOGOUT_ERROR], message: getErrorMessage(ERROR_CODES.AUTH.LOGOUT_ERROR),
}, },
}, },
{ status: 500 } { status: 500 }

View File

@@ -1,8 +1,8 @@
import { NextResponse } from "next/server"; import { NextResponse } from "next/server";
import { AuthServerService, UserData } from "@/lib/services/auth-server.service"; import { AuthServerService, UserData } from "@/lib/services/auth-server.service";
import { ERROR_CODES } from "@/constants/errorCodes"; import { ERROR_CODES } from "@/constants/errorCodes";
import { ERROR_MESSAGES } from "@/constants/errorMessages";
import { AppError } from "@/utils/errors"; import { AppError } from "@/utils/errors";
import { getErrorMessage } from "@/utils/errors";
export async function POST(request: Request) { export async function POST(request: Request) {
try { try {
@@ -27,7 +27,7 @@ export async function POST(request: Request) {
{ {
error: { error: {
code: error.code, code: error.code,
message: ERROR_MESSAGES[error.code], message: getErrorMessage(error.code),
}, },
}, },
{ status } { status }
@@ -41,7 +41,7 @@ export async function POST(request: Request) {
{ {
error: { error: {
code: ERROR_CODES.AUTH.INVALID_USER_DATA, code: ERROR_CODES.AUTH.INVALID_USER_DATA,
message: ERROR_MESSAGES[ERROR_CODES.AUTH.INVALID_USER_DATA], message: getErrorMessage(ERROR_CODES.AUTH.INVALID_USER_DATA),
}, },
}, },
{ status: 500 } { status: 500 }

View File

@@ -1,7 +1,7 @@
import { NextRequest, NextResponse } from "next/server"; import { NextRequest, NextResponse } from "next/server";
import { DebugService, RequestTiming } from "@/lib/services/debug.service"; import { DebugService, RequestTiming } from "@/lib/services/debug.service";
import { ERROR_CODES } from "@/constants/errorCodes"; import { ERROR_CODES } from "@/constants/errorCodes";
import { ERROR_MESSAGES } from "@/constants/errorMessages"; import { getErrorMessage } from "@/utils/errors";
import { AppError } from "@/utils/errors"; import { AppError } from "@/utils/errors";
export async function GET() { export async function GET() {
@@ -15,7 +15,7 @@ export async function GET() {
{ {
error: { error: {
code: error.code, code: error.code,
message: ERROR_MESSAGES[error.code], message: getErrorMessage(error.code),
}, },
}, },
{ status: 500 } { status: 500 }
@@ -25,7 +25,7 @@ export async function GET() {
{ {
error: { error: {
code: ERROR_CODES.DEBUG.FETCH_ERROR, code: ERROR_CODES.DEBUG.FETCH_ERROR,
message: ERROR_MESSAGES[ERROR_CODES.DEBUG.FETCH_ERROR], message: getErrorMessage(ERROR_CODES.DEBUG.FETCH_ERROR),
}, },
}, },
{ status: 500 } { status: 500 }
@@ -47,7 +47,7 @@ export async function POST(request: NextRequest) {
{ {
error: { error: {
code: error.code, code: error.code,
message: ERROR_MESSAGES[error.code], message: getErrorMessage(error.code),
}, },
}, },
{ status: 500 } { status: 500 }
@@ -57,7 +57,7 @@ export async function POST(request: NextRequest) {
{ {
error: { error: {
code: ERROR_CODES.DEBUG.SAVE_ERROR, code: ERROR_CODES.DEBUG.SAVE_ERROR,
message: ERROR_MESSAGES[ERROR_CODES.DEBUG.SAVE_ERROR], message: getErrorMessage(ERROR_CODES.DEBUG.SAVE_ERROR),
}, },
}, },
{ status: 500 } { status: 500 }
@@ -78,7 +78,7 @@ export async function DELETE() {
{ {
error: { error: {
code: error.code, code: error.code,
message: ERROR_MESSAGES[error.code], message: getErrorMessage(error.code),
}, },
}, },
{ status: 500 } { status: 500 }
@@ -88,7 +88,7 @@ export async function DELETE() {
{ {
error: { error: {
code: ERROR_CODES.DEBUG.CLEAR_ERROR, code: ERROR_CODES.DEBUG.CLEAR_ERROR,
message: ERROR_MESSAGES[ERROR_CODES.DEBUG.CLEAR_ERROR], message: getErrorMessage(ERROR_CODES.DEBUG.CLEAR_ERROR),
}, },
}, },
{ status: 500 } { status: 500 }

View File

@@ -1,7 +1,7 @@
import { NextRequest, NextResponse } from "next/server"; import { NextRequest, NextResponse } from "next/server";
import { BookService } from "@/lib/services/book.service"; import { BookService } from "@/lib/services/book.service";
import { ERROR_CODES } from "@/constants/errorCodes"; import { ERROR_CODES } from "@/constants/errorCodes";
import { ERROR_MESSAGES } from "@/constants/errorMessages"; import { getErrorMessage } from "@/utils/errors";
import { AppError } from "@/utils/errors"; import { AppError } from "@/utils/errors";
export const dynamic = "force-dynamic"; export const dynamic = "force-dynamic";
@@ -17,7 +17,7 @@ export async function GET(
{ {
error: { error: {
code: ERROR_CODES.IMAGE.FETCH_ERROR, code: ERROR_CODES.IMAGE.FETCH_ERROR,
message: ERROR_MESSAGES[ERROR_CODES.IMAGE.FETCH_ERROR], message: getErrorMessage(ERROR_CODES.IMAGE.FETCH_ERROR),
}, },
}, },
{ status: 400 } { status: 400 }
@@ -41,7 +41,7 @@ export async function GET(
{ {
error: { error: {
code: error.code, code: error.code,
message: ERROR_MESSAGES[error.code], message: getErrorMessage(error.code),
}, },
}, },
{ status: 500 } { status: 500 }
@@ -51,7 +51,7 @@ export async function GET(
{ {
error: { error: {
code: ERROR_CODES.IMAGE.FETCH_ERROR, code: ERROR_CODES.IMAGE.FETCH_ERROR,
message: ERROR_MESSAGES[ERROR_CODES.IMAGE.FETCH_ERROR], message: getErrorMessage(ERROR_CODES.IMAGE.FETCH_ERROR),
}, },
}, },
{ status: 500 } { status: 500 }

View File

@@ -1,7 +1,7 @@
import { NextRequest, NextResponse } from "next/server"; import { NextRequest, NextResponse } from "next/server";
import { BookService } from "@/lib/services/book.service"; import { BookService } from "@/lib/services/book.service";
import { ERROR_CODES } from "@/constants/errorCodes"; import { ERROR_CODES } from "@/constants/errorCodes";
import { ERROR_MESSAGES } from "@/constants/errorMessages"; import { getErrorMessage } from "@/utils/errors";
import { AppError } from "@/utils/errors"; import { AppError } from "@/utils/errors";
export async function PATCH(request: NextRequest, { params }: { params: { bookId: string } }) { export async function PATCH(request: NextRequest, { params }: { params: { bookId: string } }) {
@@ -13,7 +13,7 @@ export async function PATCH(request: NextRequest, { params }: { params: { bookId
{ {
error: { error: {
code: ERROR_CODES.BOOK.PROGRESS_UPDATE_ERROR, code: ERROR_CODES.BOOK.PROGRESS_UPDATE_ERROR,
message: ERROR_MESSAGES[ERROR_CODES.BOOK.PROGRESS_UPDATE_ERROR], message: getErrorMessage(ERROR_CODES.BOOK.PROGRESS_UPDATE_ERROR),
}, },
}, },
{ status: 400 } { status: 400 }
@@ -29,7 +29,7 @@ export async function PATCH(request: NextRequest, { params }: { params: { bookId
{ {
error: { error: {
code: error.code, code: error.code,
message: ERROR_MESSAGES[error.code], message: getErrorMessage(error.code),
}, },
}, },
{ status: 500 } { status: 500 }
@@ -39,7 +39,7 @@ export async function PATCH(request: NextRequest, { params }: { params: { bookId
{ {
error: { error: {
code: ERROR_CODES.BOOK.PROGRESS_UPDATE_ERROR, code: ERROR_CODES.BOOK.PROGRESS_UPDATE_ERROR,
message: ERROR_MESSAGES[ERROR_CODES.BOOK.PROGRESS_UPDATE_ERROR], message: getErrorMessage(ERROR_CODES.BOOK.PROGRESS_UPDATE_ERROR),
}, },
}, },
{ status: 500 } { status: 500 }
@@ -58,7 +58,7 @@ export async function DELETE(request: NextRequest, { params }: { params: { bookI
{ {
error: { error: {
code: error.code, code: error.code,
message: ERROR_MESSAGES[error.code], message: getErrorMessage(error.code),
}, },
}, },
{ status: 500 } { status: 500 }
@@ -68,7 +68,7 @@ export async function DELETE(request: NextRequest, { params }: { params: { bookI
{ {
error: { error: {
code: ERROR_CODES.BOOK.PROGRESS_DELETE_ERROR, code: ERROR_CODES.BOOK.PROGRESS_DELETE_ERROR,
message: ERROR_MESSAGES[ERROR_CODES.BOOK.PROGRESS_DELETE_ERROR], message: getErrorMessage(ERROR_CODES.BOOK.PROGRESS_DELETE_ERROR),
}, },
}, },
{ status: 500 } { status: 500 }

View File

@@ -1,7 +1,7 @@
import { NextResponse } from "next/server"; import { NextResponse } from "next/server";
import { BookService } from "@/lib/services/book.service"; import { BookService } from "@/lib/services/book.service";
import { ERROR_CODES } from "@/constants/errorCodes"; import { ERROR_CODES } from "@/constants/errorCodes";
import { ERROR_MESSAGES } from "@/constants/errorMessages"; import { getErrorMessage } from "@/utils/errors";
import { AppError } from "@/utils/errors"; import { AppError } from "@/utils/errors";
import { KomgaBookWithPages } from "@/types/komga"; import { KomgaBookWithPages } from "@/types/komga";
export async function GET(request: Request, { params }: { params: { bookId: string } }) { export async function GET(request: Request, { params }: { params: { bookId: string } }) {
@@ -15,7 +15,7 @@ export async function GET(request: Request, { params }: { params: { bookId: stri
{ {
error: { error: {
code: error.code, code: error.code,
message: ERROR_MESSAGES[error.code], message: getErrorMessage(error.code),
}, },
}, },
{ status: 500 } { status: 500 }
@@ -25,7 +25,7 @@ export async function GET(request: Request, { params }: { params: { bookId: stri
{ {
error: { error: {
code: ERROR_CODES.BOOK.NOT_FOUND, code: ERROR_CODES.BOOK.NOT_FOUND,
message: ERROR_MESSAGES[ERROR_CODES.BOOK.NOT_FOUND], message: getErrorMessage(ERROR_CODES.BOOK.NOT_FOUND),
}, },
}, },
{ status: 500 } { status: 500 }

View File

@@ -1,7 +1,7 @@
import { NextResponse } from "next/server"; import { NextResponse } from "next/server";
import { getServerCacheService, ServerCacheService } from "@/lib/services/server-cache.service"; import { getServerCacheService, ServerCacheService } from "@/lib/services/server-cache.service";
import { ERROR_CODES } from "@/constants/errorCodes"; import { ERROR_CODES } from "@/constants/errorCodes";
import { ERROR_MESSAGES } from "@/constants/errorMessages"; import { getErrorMessage } from "@/utils/errors";
export async function POST() { export async function POST() {
try { try {
@@ -14,7 +14,7 @@ export async function POST() {
{ {
error: { error: {
code: ERROR_CODES.CACHE.CLEAR_ERROR, code: ERROR_CODES.CACHE.CLEAR_ERROR,
message: ERROR_MESSAGES[ERROR_CODES.CACHE.CLEAR_ERROR], message: getErrorMessage(ERROR_CODES.CACHE.CLEAR_ERROR),
}, },
}, },
{ status: 500 } { status: 500 }

View File

@@ -5,7 +5,7 @@ import {
ServerCacheService, ServerCacheService,
} from "@/lib/services/server-cache.service"; } from "@/lib/services/server-cache.service";
import { ERROR_CODES } from "@/constants/errorCodes"; import { ERROR_CODES } from "@/constants/errorCodes";
import { ERROR_MESSAGES } from "@/constants/errorMessages"; import { getErrorMessage } from "@/utils/errors";
export async function GET() { export async function GET() {
try { try {
@@ -17,7 +17,7 @@ export async function GET() {
{ {
error: { error: {
code: ERROR_CODES.CACHE.MODE_FETCH_ERROR, code: ERROR_CODES.CACHE.MODE_FETCH_ERROR,
message: ERROR_MESSAGES[ERROR_CODES.CACHE.MODE_FETCH_ERROR], message: getErrorMessage(ERROR_CODES.CACHE.MODE_FETCH_ERROR),
}, },
}, },
{ status: 500 } { status: 500 }
@@ -33,7 +33,7 @@ export async function POST(request: Request) {
{ {
error: { error: {
code: ERROR_CODES.CACHE.INVALID_MODE, code: ERROR_CODES.CACHE.INVALID_MODE,
message: ERROR_MESSAGES[ERROR_CODES.CACHE.INVALID_MODE], message: getErrorMessage(ERROR_CODES.CACHE.INVALID_MODE),
}, },
}, },
{ status: 400 } { status: 400 }
@@ -49,7 +49,7 @@ export async function POST(request: Request) {
{ {
error: { error: {
code: ERROR_CODES.CACHE.MODE_UPDATE_ERROR, code: ERROR_CODES.CACHE.MODE_UPDATE_ERROR,
message: ERROR_MESSAGES[ERROR_CODES.CACHE.MODE_UPDATE_ERROR], message: getErrorMessage(ERROR_CODES.CACHE.MODE_UPDATE_ERROR),
}, },
}, },
{ status: 500 } { status: 500 }

View File

@@ -1,8 +1,8 @@
import { NextResponse } from "next/server"; import { NextResponse } from "next/server";
import { ConfigDBService } from "@/lib/services/config-db.service"; import { ConfigDBService } from "@/lib/services/config-db.service";
import { ERROR_CODES } from "@/constants/errorCodes"; import { ERROR_CODES } from "@/constants/errorCodes";
import { ERROR_MESSAGES } from "@/constants/errorMessages";
import { KomgaConfig, KomgaConfigData } from "@/types/komga"; import { KomgaConfig, KomgaConfigData } from "@/types/komga";
import { getErrorMessage } from "@/utils/errors";
export const dynamic = "force-dynamic"; export const dynamic = "force-dynamic";
@@ -22,7 +22,7 @@ export async function POST(request: Request) {
{ {
error: { error: {
code: ERROR_CODES.MIDDLEWARE.UNAUTHORIZED, code: ERROR_CODES.MIDDLEWARE.UNAUTHORIZED,
message: ERROR_MESSAGES[ERROR_CODES.MIDDLEWARE.UNAUTHORIZED], message: getErrorMessage(ERROR_CODES.MIDDLEWARE.UNAUTHORIZED),
}, },
}, },
{ status: 401 } { status: 401 }
@@ -32,7 +32,7 @@ export async function POST(request: Request) {
{ {
error: { error: {
code: ERROR_CODES.CONFIG.SAVE_ERROR, code: ERROR_CODES.CONFIG.SAVE_ERROR,
message: ERROR_MESSAGES[ERROR_CODES.CONFIG.SAVE_ERROR], message: getErrorMessage(ERROR_CODES.CONFIG.SAVE_ERROR),
}, },
}, },
{ status: 500 } { status: 500 }
@@ -53,7 +53,7 @@ export async function GET() {
{ {
error: { error: {
code: ERROR_CODES.MIDDLEWARE.UNAUTHORIZED, code: ERROR_CODES.MIDDLEWARE.UNAUTHORIZED,
message: ERROR_MESSAGES[ERROR_CODES.MIDDLEWARE.UNAUTHORIZED], message: getErrorMessage(ERROR_CODES.MIDDLEWARE.UNAUTHORIZED),
}, },
}, },
{ status: 401 } { status: 401 }
@@ -64,7 +64,7 @@ export async function GET() {
{ {
error: { error: {
code: ERROR_CODES.KOMGA.MISSING_CONFIG, code: ERROR_CODES.KOMGA.MISSING_CONFIG,
message: ERROR_MESSAGES[ERROR_CODES.KOMGA.MISSING_CONFIG], message: getErrorMessage(ERROR_CODES.KOMGA.MISSING_CONFIG),
}, },
}, },
{ status: 404 } { status: 404 }
@@ -75,7 +75,7 @@ export async function GET() {
{ {
error: { error: {
code: ERROR_CODES.CONFIG.FETCH_ERROR, code: ERROR_CODES.CONFIG.FETCH_ERROR,
message: ERROR_MESSAGES[ERROR_CODES.CONFIG.FETCH_ERROR], message: getErrorMessage(ERROR_CODES.CONFIG.FETCH_ERROR),
}, },
}, },
{ status: 500 } { status: 500 }

View File

@@ -1,8 +1,8 @@
import { NextResponse } from "next/server"; import { NextResponse } from "next/server";
import { FavoriteService } from "@/lib/services/favorite.service"; import { FavoriteService } from "@/lib/services/favorite.service";
import { ERROR_CODES } from "@/constants/errorCodes"; import { ERROR_CODES } from "@/constants/errorCodes";
import { ERROR_MESSAGES } from "@/constants/errorMessages";
import { AppError } from "@/utils/errors"; import { AppError } from "@/utils/errors";
import { getErrorMessage } from "@/utils/errors";
export async function GET() { export async function GET() {
try { try {
@@ -15,7 +15,7 @@ export async function GET() {
{ {
error: { error: {
code: error.code, code: error.code,
message: ERROR_MESSAGES[error.code], message: getErrorMessage(error.code),
}, },
}, },
{ status: 500 } { status: 500 }
@@ -25,7 +25,7 @@ export async function GET() {
{ {
error: { error: {
code: ERROR_CODES.FAVORITE.FETCH_ERROR, code: ERROR_CODES.FAVORITE.FETCH_ERROR,
message: ERROR_MESSAGES[ERROR_CODES.FAVORITE.FETCH_ERROR], message: getErrorMessage(ERROR_CODES.FAVORITE.FETCH_ERROR),
}, },
}, },
{ status: 500 } { status: 500 }
@@ -45,7 +45,7 @@ export async function POST(request: Request) {
{ {
error: { error: {
code: error.code, code: error.code,
message: ERROR_MESSAGES[error.code], message: getErrorMessage(error.code),
}, },
}, },
{ status: 500 } { status: 500 }
@@ -55,7 +55,7 @@ export async function POST(request: Request) {
{ {
error: { error: {
code: ERROR_CODES.FAVORITE.ADD_ERROR, code: ERROR_CODES.FAVORITE.ADD_ERROR,
message: ERROR_MESSAGES[ERROR_CODES.FAVORITE.ADD_ERROR], message: getErrorMessage(ERROR_CODES.FAVORITE.ADD_ERROR),
}, },
}, },
{ status: 500 } { status: 500 }
@@ -75,7 +75,7 @@ export async function DELETE(request: Request) {
{ {
error: { error: {
code: error.code, code: error.code,
message: ERROR_MESSAGES[error.code], message: getErrorMessage(error.code),
}, },
}, },
{ status: 500 } { status: 500 }
@@ -85,7 +85,7 @@ export async function DELETE(request: Request) {
{ {
error: { error: {
code: ERROR_CODES.FAVORITE.DELETE_ERROR, code: ERROR_CODES.FAVORITE.DELETE_ERROR,
message: ERROR_MESSAGES[ERROR_CODES.FAVORITE.DELETE_ERROR], message: getErrorMessage(ERROR_CODES.FAVORITE.DELETE_ERROR),
}, },
}, },
{ status: 500 } { status: 500 }

View File

@@ -1,8 +1,8 @@
import { NextRequest, NextResponse } from "next/server"; import { NextRequest, NextResponse } from "next/server";
import { BookService } from "@/lib/services/book.service"; import { BookService } from "@/lib/services/book.service";
import { ERROR_CODES } from "@/constants/errorCodes"; import { ERROR_CODES } from "@/constants/errorCodes";
import { ERROR_MESSAGES } from "@/constants/errorMessages";
import { AppError } from "@/utils/errors"; import { AppError } from "@/utils/errors";
import { getErrorMessage } from "@/utils/errors";
export const dynamic = "force-dynamic"; export const dynamic = "force-dynamic";
@@ -20,7 +20,7 @@ export async function GET(
{ {
error: { error: {
code: error.code, code: error.code,
message: ERROR_MESSAGES[error.code], message: getErrorMessage(error.code),
}, },
}, },
{ status: 500 } { status: 500 }
@@ -30,7 +30,7 @@ export async function GET(
{ {
error: { error: {
code: ERROR_CODES.IMAGE.FETCH_ERROR, code: ERROR_CODES.IMAGE.FETCH_ERROR,
message: ERROR_MESSAGES[ERROR_CODES.IMAGE.FETCH_ERROR], message: getErrorMessage(ERROR_CODES.IMAGE.FETCH_ERROR),
}, },
}, },
{ status: 500 } { status: 500 }

View File

@@ -1,8 +1,8 @@
import { NextRequest, NextResponse } from "next/server"; import { NextRequest, NextResponse } from "next/server";
import { BookService } from "@/lib/services/book.service"; import { BookService } from "@/lib/services/book.service";
import { ERROR_CODES } from "@/constants/errorCodes"; import { ERROR_CODES } from "@/constants/errorCodes";
import { ERROR_MESSAGES } from "@/constants/errorMessages";
import { AppError } from "@/utils/errors"; import { AppError } from "@/utils/errors";
import { getErrorMessage } from "@/utils/errors";
export const dynamic = "force-dynamic"; export const dynamic = "force-dynamic";
@@ -18,7 +18,7 @@ export async function GET(
{ {
error: { error: {
code: ERROR_CODES.BOOK.PAGES_FETCH_ERROR, code: ERROR_CODES.BOOK.PAGES_FETCH_ERROR,
message: ERROR_MESSAGES[ERROR_CODES.BOOK.PAGES_FETCH_ERROR], message: getErrorMessage(ERROR_CODES.BOOK.PAGES_FETCH_ERROR),
}, },
}, },
{ status: 400 } { status: 400 }
@@ -34,7 +34,7 @@ export async function GET(
{ {
error: { error: {
code: error.code, code: error.code,
message: ERROR_MESSAGES[error.code], message: getErrorMessage(error.code),
}, },
}, },
{ status: 500 } { status: 500 }
@@ -44,7 +44,7 @@ export async function GET(
{ {
error: { error: {
code: ERROR_CODES.IMAGE.FETCH_ERROR, code: ERROR_CODES.IMAGE.FETCH_ERROR,
message: ERROR_MESSAGES[ERROR_CODES.IMAGE.FETCH_ERROR], message: getErrorMessage(ERROR_CODES.IMAGE.FETCH_ERROR),
}, },
}, },
{ status: 500 } { status: 500 }

View File

@@ -1,8 +1,8 @@
import { NextRequest, NextResponse } from "next/server"; import { NextRequest, NextResponse } from "next/server";
import { BookService } from "@/lib/services/book.service"; import { BookService } from "@/lib/services/book.service";
import { ERROR_CODES } from "@/constants/errorCodes"; import { ERROR_CODES } from "@/constants/errorCodes";
import { ERROR_MESSAGES } from "@/constants/errorMessages";
import { AppError } from "@/utils/errors"; import { AppError } from "@/utils/errors";
import { getErrorMessage } from "@/utils/errors";
export async function GET(request: NextRequest, { params }: { params: { bookId: string } }) { export async function GET(request: NextRequest, { params }: { params: { bookId: string } }) {
try { try {
@@ -15,7 +15,7 @@ export async function GET(request: NextRequest, { params }: { params: { bookId:
{ {
error: { error: {
code: error.code, code: error.code,
message: ERROR_MESSAGES[error.code], message: getErrorMessage(error.code),
}, },
}, },
{ status: 500 } { status: 500 }
@@ -25,7 +25,7 @@ export async function GET(request: NextRequest, { params }: { params: { bookId:
{ {
error: { error: {
code: ERROR_CODES.IMAGE.FETCH_ERROR, code: ERROR_CODES.IMAGE.FETCH_ERROR,
message: ERROR_MESSAGES[ERROR_CODES.IMAGE.FETCH_ERROR], message: getErrorMessage(ERROR_CODES.IMAGE.FETCH_ERROR),
}, },
}, },
{ status: 500 } { status: 500 }

View File

@@ -1,8 +1,8 @@
import { NextRequest, NextResponse } from "next/server"; import { NextRequest, NextResponse } from "next/server";
import { SeriesService } from "@/lib/services/series.service"; import { SeriesService } from "@/lib/services/series.service";
import { ERROR_CODES } from "@/constants/errorCodes"; import { ERROR_CODES } from "@/constants/errorCodes";
import { ERROR_MESSAGES } from "@/constants/errorMessages";
import { AppError } from "@/utils/errors"; import { AppError } from "@/utils/errors";
import { getErrorMessage } from "@/utils/errors";
export const dynamic = "force-dynamic"; export const dynamic = "force-dynamic";
@@ -17,7 +17,7 @@ export async function GET(request: NextRequest, { params }: { params: { seriesId
{ {
error: { error: {
code: error.code, code: error.code,
message: ERROR_MESSAGES[error.code], message: getErrorMessage(error.code),
}, },
}, },
{ status: 500 } { status: 500 }
@@ -27,7 +27,7 @@ export async function GET(request: NextRequest, { params }: { params: { seriesId
{ {
error: { error: {
code: ERROR_CODES.IMAGE.FETCH_ERROR, code: ERROR_CODES.IMAGE.FETCH_ERROR,
message: ERROR_MESSAGES[ERROR_CODES.IMAGE.FETCH_ERROR], message: getErrorMessage(ERROR_CODES.IMAGE.FETCH_ERROR),
}, },
}, },
{ status: 500 } { status: 500 }

View File

@@ -1,8 +1,8 @@
import { NextRequest, NextResponse } from "next/server"; import { NextRequest, NextResponse } from "next/server";
import { SeriesService } from "@/lib/services/series.service"; import { SeriesService } from "@/lib/services/series.service";
import { ERROR_CODES } from "@/constants/errorCodes"; import { ERROR_CODES } from "@/constants/errorCodes";
import { ERROR_MESSAGES } from "@/constants/errorMessages";
import { AppError } from "@/utils/errors"; import { AppError } from "@/utils/errors";
import { getErrorMessage } from "@/utils/errors";
export async function GET(request: NextRequest, { params }: { params: { seriesId: string } }) { export async function GET(request: NextRequest, { params }: { params: { seriesId: string } }) {
try { try {
@@ -15,7 +15,7 @@ export async function GET(request: NextRequest, { params }: { params: { seriesId
{ {
error: { error: {
code: error.code, code: error.code,
message: ERROR_MESSAGES[error.code], message: getErrorMessage(error.code),
}, },
}, },
{ status: 500 } { status: 500 }
@@ -25,7 +25,7 @@ export async function GET(request: NextRequest, { params }: { params: { seriesId
{ {
error: { error: {
code: ERROR_CODES.IMAGE.FETCH_ERROR, code: ERROR_CODES.IMAGE.FETCH_ERROR,
message: ERROR_MESSAGES[ERROR_CODES.IMAGE.FETCH_ERROR], message: getErrorMessage(ERROR_CODES.IMAGE.FETCH_ERROR),
}, },
}, },
{ status: 500 } { status: 500 }

View File

@@ -1,9 +1,9 @@
import { NextResponse } from "next/server"; import { NextResponse } from "next/server";
import { LibraryService } from "@/lib/services/library.service"; import { LibraryService } from "@/lib/services/library.service";
import { ERROR_CODES } from "@/constants/errorCodes"; import { ERROR_CODES } from "@/constants/errorCodes";
import { ERROR_MESSAGES } from "@/constants/errorMessages";
import { AppError } from "@/utils/errors"; import { AppError } from "@/utils/errors";
import { KomgaLibrary } from "@/types/komga"; import { KomgaLibrary } from "@/types/komga";
import { getErrorMessage } from "@/utils/errors";
export const dynamic = "force-dynamic"; export const dynamic = "force-dynamic";
export async function GET() { export async function GET() {
@@ -17,7 +17,7 @@ export async function GET() {
{ {
error: { error: {
code: error.code, code: error.code,
message: ERROR_MESSAGES[error.code], message: getErrorMessage(error.code),
}, },
}, },
{ status: 500 } { status: 500 }
@@ -27,7 +27,7 @@ export async function GET() {
{ {
error: { error: {
code: ERROR_CODES.LIBRARY.FETCH_ERROR, code: ERROR_CODES.LIBRARY.FETCH_ERROR,
message: ERROR_MESSAGES[ERROR_CODES.LIBRARY.FETCH_ERROR], message: getErrorMessage(ERROR_CODES.LIBRARY.FETCH_ERROR),
}, },
}, },
{ status: 500 } { status: 500 }

View File

@@ -1,9 +1,9 @@
import { NextResponse } from "next/server"; import { NextResponse } from "next/server";
import { SeriesService } from "@/lib/services/series.service"; import { SeriesService } from "@/lib/services/series.service";
import { ERROR_CODES } from "@/constants/errorCodes"; import { ERROR_CODES } from "@/constants/errorCodes";
import { ERROR_MESSAGES } from "@/constants/errorMessages";
import { AppError } from "@/utils/errors"; import { AppError } from "@/utils/errors";
import { KomgaSeries } from "@/types/komga"; import { KomgaSeries } from "@/types/komga";
import { getErrorMessage } from "@/utils/errors";
export const dynamic = "force-dynamic"; export const dynamic = "force-dynamic";
@@ -18,7 +18,7 @@ export async function GET(request: Request, { params }: { params: { seriesId: st
{ {
error: { error: {
code: error.code, code: error.code,
message: ERROR_MESSAGES[error.code], message: getErrorMessage(error.code),
}, },
}, },
{ status: 500 } { status: 500 }
@@ -28,7 +28,7 @@ export async function GET(request: Request, { params }: { params: { seriesId: st
{ {
error: { error: {
code: ERROR_CODES.SERIES.FETCH_ERROR, code: ERROR_CODES.SERIES.FETCH_ERROR,
message: ERROR_MESSAGES[ERROR_CODES.SERIES.FETCH_ERROR], message: getErrorMessage(ERROR_CODES.SERIES.FETCH_ERROR),
}, },
}, },
{ status: 500 } { status: 500 }

View File

@@ -1,7 +1,7 @@
import { NextResponse } from "next/server"; import { NextResponse } from "next/server";
import { TestService } from "@/lib/services/test.service"; import { TestService } from "@/lib/services/test.service";
import { ERROR_CODES } from "@/constants/errorCodes"; import { ERROR_CODES } from "@/constants/errorCodes";
import { ERROR_MESSAGES } from "@/constants/errorMessages"; import { getErrorMessage } from "@/utils/errors";
import { KomgaLibrary } from "@/types/komga"; import { KomgaLibrary } from "@/types/komga";
export async function POST(request: Request) { export async function POST(request: Request) {
@@ -25,7 +25,7 @@ export async function POST(request: Request) {
{ {
error: { error: {
code: ERROR_CODES.KOMGA.CONNECTION_ERROR, code: ERROR_CODES.KOMGA.CONNECTION_ERROR,
message: ERROR_MESSAGES[ERROR_CODES.KOMGA.CONNECTION_ERROR], message: getErrorMessage(ERROR_CODES.KOMGA.CONNECTION_ERROR),
}, },
}, },
{ status: 400 } { status: 400 }

View File

@@ -1,8 +1,8 @@
import { NextResponse } from "next/server"; import { NextResponse } from "next/server";
import { ConfigDBService } from "@/lib/services/config-db.service"; import { ConfigDBService } from "@/lib/services/config-db.service";
import { ERROR_CODES } from "@/constants/errorCodes"; import { ERROR_CODES } from "@/constants/errorCodes";
import { ERROR_MESSAGES } from "@/constants/errorMessages";
import { TTLConfig } from "@/types/komga"; import { TTLConfig } from "@/types/komga";
import { getErrorMessage } from "@/utils/errors";
export async function GET() { export async function GET() {
try { try {
@@ -16,7 +16,7 @@ export async function GET() {
{ {
error: { error: {
code: ERROR_CODES.MIDDLEWARE.UNAUTHORIZED, code: ERROR_CODES.MIDDLEWARE.UNAUTHORIZED,
message: ERROR_MESSAGES[ERROR_CODES.MIDDLEWARE.UNAUTHORIZED], message: getErrorMessage(ERROR_CODES.MIDDLEWARE.UNAUTHORIZED),
}, },
}, },
{ status: 401 } { status: 401 }
@@ -27,7 +27,7 @@ export async function GET() {
{ {
error: { error: {
code: ERROR_CODES.CONFIG.TTL_FETCH_ERROR, code: ERROR_CODES.CONFIG.TTL_FETCH_ERROR,
message: ERROR_MESSAGES[ERROR_CODES.CONFIG.TTL_FETCH_ERROR], message: getErrorMessage(ERROR_CODES.CONFIG.TTL_FETCH_ERROR),
}, },
}, },
{ status: 500 } { status: 500 }
@@ -58,7 +58,7 @@ export async function POST(request: Request) {
{ {
error: { error: {
code: ERROR_CODES.MIDDLEWARE.UNAUTHORIZED, code: ERROR_CODES.MIDDLEWARE.UNAUTHORIZED,
message: ERROR_MESSAGES[ERROR_CODES.MIDDLEWARE.UNAUTHORIZED], message: getErrorMessage(ERROR_CODES.MIDDLEWARE.UNAUTHORIZED),
}, },
}, },
{ status: 401 } { status: 401 }
@@ -68,7 +68,7 @@ export async function POST(request: Request) {
{ {
error: { error: {
code: ERROR_CODES.CONFIG.TTL_SAVE_ERROR, code: ERROR_CODES.CONFIG.TTL_SAVE_ERROR,
message: ERROR_MESSAGES[ERROR_CODES.CONFIG.TTL_SAVE_ERROR], message: getErrorMessage(ERROR_CODES.CONFIG.TTL_SAVE_ERROR),
}, },
}, },
{ status: 500 } { status: 500 }

View File

@@ -1,9 +1,9 @@
import { NextRequest, NextResponse } from "next/server"; import { NextRequest, NextResponse } from "next/server";
import { PreferencesService } from "@/lib/services/preferences.service"; import { PreferencesService } from "@/lib/services/preferences.service";
import { ERROR_CODES } from "@/constants/errorCodes"; import { ERROR_CODES } from "@/constants/errorCodes";
import { ERROR_MESSAGES } from "@/constants/errorMessages";
import { AppError } from "@/utils/errors"; import { AppError } from "@/utils/errors";
import { UserPreferences } from "@/types/preferences"; import { UserPreferences } from "@/types/preferences";
import { getErrorMessage } from "@/utils/errors";
export async function GET() { export async function GET() {
try { try {
@@ -16,7 +16,7 @@ export async function GET() {
{ {
error: { error: {
code: error.code, code: error.code,
message: ERROR_MESSAGES[error.code], message: getErrorMessage(error.code),
}, },
}, },
{ status: 500 } { status: 500 }
@@ -26,7 +26,7 @@ export async function GET() {
{ {
error: { error: {
code: ERROR_CODES.PREFERENCES.FETCH_ERROR, code: ERROR_CODES.PREFERENCES.FETCH_ERROR,
message: ERROR_MESSAGES[ERROR_CODES.PREFERENCES.FETCH_ERROR], message: getErrorMessage(ERROR_CODES.PREFERENCES.FETCH_ERROR),
}, },
}, },
{ status: 500 } { status: 500 }
@@ -48,7 +48,7 @@ export async function PUT(request: NextRequest) {
{ {
error: { error: {
code: error.code, code: error.code,
message: ERROR_MESSAGES[error.code], message: getErrorMessage(error.code),
}, },
}, },
{ status: 500 } { status: 500 }
@@ -58,7 +58,7 @@ export async function PUT(request: NextRequest) {
{ {
error: { error: {
code: ERROR_CODES.PREFERENCES.UPDATE_ERROR, code: ERROR_CODES.PREFERENCES.UPDATE_ERROR,
message: ERROR_MESSAGES[ERROR_CODES.PREFERENCES.UPDATE_ERROR], message: getErrorMessage(ERROR_CODES.PREFERENCES.UPDATE_ERROR),
}, },
}, },
{ status: 500 } { status: 500 }

View File

@@ -5,7 +5,7 @@ import { useRouter } from "next/navigation";
import { authService } from "@/lib/services/auth.service"; import { authService } from "@/lib/services/auth.service";
import { AuthError } from "@/types/auth"; import { AuthError } from "@/types/auth";
import { ERROR_CODES } from "@/constants/errorCodes"; import { ERROR_CODES } from "@/constants/errorCodes";
import { ERROR_MESSAGES } from "@/constants/errorMessages"; import { getErrorMessage } from "@/utils/errors";
import { ErrorMessage } from "@/components/ui/ErrorMessage"; import { ErrorMessage } from "@/components/ui/ErrorMessage";
import { useTranslate } from "@/hooks/useTranslate"; import { useTranslate } from "@/hooks/useTranslate";
@@ -32,7 +32,7 @@ export function RegisterForm({ from }: RegisterFormProps) {
if (password !== confirmPassword) { if (password !== confirmPassword) {
setError({ setError({
code: ERROR_CODES.AUTH.PASSWORD_MISMATCH, code: ERROR_CODES.AUTH.PASSWORD_MISMATCH,
message: ERROR_MESSAGES[ERROR_CODES.AUTH.PASSWORD_MISMATCH], message: getErrorMessage(ERROR_CODES.AUTH.PASSWORD_MISMATCH),
}); });
setIsLoading(false); setIsLoading(false);
return; return;

View File

@@ -9,7 +9,7 @@ import { KomgaLibrary, KomgaSeries } from "@/types/komga";
import { usePreferences } from "@/contexts/PreferencesContext"; import { usePreferences } from "@/contexts/PreferencesContext";
import { AppError } from "@/utils/errors"; import { AppError } from "@/utils/errors";
import { ERROR_CODES } from "@/constants/errorCodes"; import { ERROR_CODES } from "@/constants/errorCodes";
import { ERROR_MESSAGES } from "@/constants/errorMessages"; import { getErrorMessage } from "@/utils/errors";
import { useToast } from "@/components/ui/use-toast"; import { useToast } from "@/components/ui/use-toast";
import { useTranslate } from "@/hooks/useTranslate"; import { useTranslate } from "@/hooks/useTranslate";
@@ -47,7 +47,7 @@ export function Sidebar({ isOpen, onClose }: SidebarProps) {
description: description:
error instanceof AppError error instanceof AppError
? error.message ? error.message
: ERROR_MESSAGES[ERROR_CODES.LIBRARY.FETCH_ERROR], : getErrorMessage(ERROR_CODES.LIBRARY.FETCH_ERROR),
variant: "destructive", variant: "destructive",
}); });
setLibraries([]); setLibraries([]);
@@ -88,7 +88,7 @@ export function Sidebar({ isOpen, onClose }: SidebarProps) {
description: description:
error instanceof AppError error instanceof AppError
? error.message ? error.message
: ERROR_MESSAGES[ERROR_CODES.FAVORITE.FETCH_ERROR], : getErrorMessage(ERROR_CODES.FAVORITE.FETCH_ERROR),
variant: "destructive", variant: "destructive",
}); });
setFavorites([]); setFavorites([]);
@@ -139,7 +139,9 @@ export function Sidebar({ isOpen, onClose }: SidebarProps) {
toast({ toast({
title: "Erreur", title: "Erreur",
description: description:
error instanceof AppError ? error.message : ERROR_MESSAGES[ERROR_CODES.AUTH.LOGOUT_ERROR], error instanceof AppError
? error.message
: getErrorMessage(ERROR_CODES.AUTH.LOGOUT_ERROR),
variant: "destructive", variant: "destructive",
}); });
} }

View File

@@ -9,7 +9,7 @@ import { Cover } from "@/components/ui/cover";
import { RefreshButton } from "@/components/library/RefreshButton"; import { RefreshButton } from "@/components/library/RefreshButton";
import { AppError } from "@/utils/errors"; import { AppError } from "@/utils/errors";
import { ERROR_CODES } from "@/constants/errorCodes"; import { ERROR_CODES } from "@/constants/errorCodes";
import { ERROR_MESSAGES } from "@/constants/errorMessages"; import { getErrorMessage } from "@/utils/errors";
import { useTranslate } from "@/hooks/useTranslate"; import { useTranslate } from "@/hooks/useTranslate";
interface SeriesHeaderProps { interface SeriesHeaderProps {
@@ -38,7 +38,7 @@ export const SeriesHeader = ({ series, refreshSeries }: SeriesHeaderProps) => {
description: description:
error instanceof AppError error instanceof AppError
? error.message ? error.message
: ERROR_MESSAGES[ERROR_CODES.FAVORITE.NETWORK_ERROR], : getErrorMessage(ERROR_CODES.FAVORITE.NETWORK_ERROR),
variant: "destructive", variant: "destructive",
}); });
} }
@@ -80,7 +80,7 @@ export const SeriesHeader = ({ series, refreshSeries }: SeriesHeaderProps) => {
description: description:
error instanceof AppError error instanceof AppError
? error.message ? error.message
: ERROR_MESSAGES[ERROR_CODES.FAVORITE.NETWORK_ERROR], : getErrorMessage(ERROR_CODES.FAVORITE.NETWORK_ERROR),
variant: "destructive", variant: "destructive",
}); });
} }

View File

@@ -2,7 +2,7 @@
import { AuthError } from "@/types/auth"; import { AuthError } from "@/types/auth";
import { ERROR_CODES } from "@/constants/errorCodes"; import { ERROR_CODES } from "@/constants/errorCodes";
import { ERROR_MESSAGES } from "@/constants/errorMessages"; import { getErrorMessage } from "@/utils/errors";
class AuthService { class AuthService {
private static instance: AuthService; private static instance: AuthService;
@@ -42,7 +42,7 @@ class AuthService {
} }
throw { throw {
code: ERROR_CODES.AUTH.INVALID_CREDENTIALS, code: ERROR_CODES.AUTH.INVALID_CREDENTIALS,
message: ERROR_MESSAGES[ERROR_CODES.AUTH.INVALID_CREDENTIALS], message: getErrorMessage(ERROR_CODES.AUTH.INVALID_CREDENTIALS),
} as AuthError; } as AuthError;
} }
} }
@@ -70,7 +70,7 @@ class AuthService {
} }
throw { throw {
code: ERROR_CODES.AUTH.INVALID_USER_DATA, code: ERROR_CODES.AUTH.INVALID_USER_DATA,
message: ERROR_MESSAGES[ERROR_CODES.AUTH.INVALID_USER_DATA], message: getErrorMessage(ERROR_CODES.AUTH.INVALID_USER_DATA),
} as AuthError; } as AuthError;
} }
} }
@@ -94,7 +94,7 @@ class AuthService {
} }
throw { throw {
code: ERROR_CODES.AUTH.LOGOUT_ERROR, code: ERROR_CODES.AUTH.LOGOUT_ERROR,
message: ERROR_MESSAGES[ERROR_CODES.AUTH.LOGOUT_ERROR], message: getErrorMessage(ERROR_CODES.AUTH.LOGOUT_ERROR),
} as AuthError; } as AuthError;
} }
} }

View File

@@ -1,8 +1,9 @@
import { NextResponse } from "next/server"; import { NextResponse } from "next/server";
import type { NextRequest } from "next/server"; import type { NextRequest } from "next/server";
import { ERROR_CODES } from "./constants/errorCodes"; import { ERROR_CODES } from "./constants/errorCodes";
import { ERROR_MESSAGES } from "./constants/errorMessages";
import { UserData } from "./lib/services/auth-server.service"; import { UserData } from "./lib/services/auth-server.service";
import { getErrorMessage } from "./utils/errors";
import i18nServer from "./i18n/i18n-server"; // Initialisation de i18n côté serveur
// Routes qui ne nécessitent pas d'authentification // Routes qui ne nécessitent pas d'authentification
const publicRoutes = ["/login", "/register", "/images"]; const publicRoutes = ["/login", "/register", "/images"];
@@ -16,10 +17,10 @@ const defaultLocale = "fr";
export function middleware(request: NextRequest) { export function middleware(request: NextRequest) {
const { pathname } = request.nextUrl; const { pathname } = request.nextUrl;
console.log("ICIIII");
// Gestion de la langue // Gestion de la langue
let locale = request.cookies.get("NEXT_LOCALE")?.value; let locale = request.cookies.get("NEXT_LOCALE")?.value;
i18nServer.changeLanguage(locale);
// Si pas de cookie de langue ou langue non supportée, on utilise la langue par défaut // Si pas de cookie de langue ou langue non supportée, on utilise la langue par défaut
if (!locale || !locales.includes(locale)) { if (!locale || !locales.includes(locale)) {
locale = defaultLocale; locale = defaultLocale;
@@ -30,7 +31,7 @@ export function middleware(request: NextRequest) {
path: "/", path: "/",
maxAge: 365 * 24 * 60 * 60, // 1 an maxAge: 365 * 24 * 60 * 60, // 1 an
}); });
i18nServer.changeLanguage(locale);
return response; return response;
} }
@@ -57,7 +58,7 @@ export function middleware(request: NextRequest) {
if (!user || !user.value) { if (!user || !user.value) {
if (pathname.startsWith("/api/")) { if (pathname.startsWith("/api/")) {
return NextResponse.json( return NextResponse.json(
{ error: ERROR_MESSAGES[ERROR_CODES.MIDDLEWARE.UNAUTHORIZED] }, { error: getErrorMessage(ERROR_CODES.MIDDLEWARE.UNAUTHORIZED) },
{ status: 401 } { status: 401 }
); );
} }
@@ -69,13 +70,13 @@ export function middleware(request: NextRequest) {
try { try {
const userData: UserData = JSON.parse(atob(user.value)); const userData: UserData = JSON.parse(atob(user.value));
if (!userData || !userData.authenticated || !userData.id || !userData.email) { if (!userData || !userData.authenticated || !userData.id || !userData.email) {
throw new Error(ERROR_MESSAGES[ERROR_CODES.MIDDLEWARE.INVALID_SESSION]); throw new Error(getErrorMessage(ERROR_CODES.MIDDLEWARE.INVALID_SESSION));
} }
} catch (error) { } catch (error) {
console.error("Erreur de validation du cookie:", error); console.error("Erreur de validation du cookie:", error);
if (pathname.startsWith("/api/")) { if (pathname.startsWith("/api/")) {
return NextResponse.json( return NextResponse.json(
{ error: ERROR_MESSAGES[ERROR_CODES.MIDDLEWARE.INVALID_TOKEN] }, { error: getErrorMessage(ERROR_CODES.MIDDLEWARE.INVALID_TOKEN) },
{ status: 401 } { status: 401 }
); );
} }