refacto: error and types
This commit is contained in:
@@ -17,6 +17,7 @@ export async function GET(
|
||||
{
|
||||
error: {
|
||||
code: ERROR_CODES.IMAGE.FETCH_ERROR,
|
||||
name: "Image fetch error",
|
||||
message: getErrorMessage(ERROR_CODES.IMAGE.FETCH_ERROR),
|
||||
},
|
||||
},
|
||||
@@ -41,6 +42,7 @@ export async function GET(
|
||||
{
|
||||
error: {
|
||||
code: error.code,
|
||||
name: "Image fetch error",
|
||||
message: getErrorMessage(error.code),
|
||||
},
|
||||
},
|
||||
@@ -51,6 +53,7 @@ export async function GET(
|
||||
{
|
||||
error: {
|
||||
code: ERROR_CODES.IMAGE.FETCH_ERROR,
|
||||
name: "Image fetch error",
|
||||
message: getErrorMessage(ERROR_CODES.IMAGE.FETCH_ERROR),
|
||||
},
|
||||
},
|
||||
|
||||
@@ -13,6 +13,7 @@ export async function PATCH(request: NextRequest, { params }: { params: { bookId
|
||||
{
|
||||
error: {
|
||||
code: ERROR_CODES.BOOK.PROGRESS_UPDATE_ERROR,
|
||||
name: "Progress update error",
|
||||
message: getErrorMessage(ERROR_CODES.BOOK.PROGRESS_UPDATE_ERROR),
|
||||
},
|
||||
},
|
||||
@@ -29,6 +30,7 @@ export async function PATCH(request: NextRequest, { params }: { params: { bookId
|
||||
{
|
||||
error: {
|
||||
code: error.code,
|
||||
name: "Progress update error",
|
||||
message: getErrorMessage(error.code),
|
||||
},
|
||||
},
|
||||
@@ -39,6 +41,7 @@ export async function PATCH(request: NextRequest, { params }: { params: { bookId
|
||||
{
|
||||
error: {
|
||||
code: ERROR_CODES.BOOK.PROGRESS_UPDATE_ERROR,
|
||||
name: "Progress update error",
|
||||
message: getErrorMessage(ERROR_CODES.BOOK.PROGRESS_UPDATE_ERROR),
|
||||
},
|
||||
},
|
||||
@@ -58,6 +61,7 @@ export async function DELETE(request: NextRequest, { params }: { params: { bookI
|
||||
{
|
||||
error: {
|
||||
code: error.code,
|
||||
name: "Progress delete error",
|
||||
message: getErrorMessage(error.code),
|
||||
},
|
||||
},
|
||||
@@ -68,6 +72,7 @@ export async function DELETE(request: NextRequest, { params }: { params: { bookI
|
||||
{
|
||||
error: {
|
||||
code: ERROR_CODES.BOOK.PROGRESS_DELETE_ERROR,
|
||||
name: "Progress delete error",
|
||||
message: getErrorMessage(ERROR_CODES.BOOK.PROGRESS_DELETE_ERROR),
|
||||
},
|
||||
},
|
||||
|
||||
@@ -15,8 +15,9 @@ export async function GET(request: Request, { params }: { params: { bookId: stri
|
||||
{
|
||||
error: {
|
||||
code: error.code,
|
||||
name: "Book fetch error",
|
||||
message: getErrorMessage(error.code),
|
||||
},
|
||||
} as AppError,
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
@@ -25,8 +26,9 @@ export async function GET(request: Request, { params }: { params: { bookId: stri
|
||||
{
|
||||
error: {
|
||||
code: ERROR_CODES.BOOK.NOT_FOUND,
|
||||
name: "Book fetch error",
|
||||
message: getErrorMessage(ERROR_CODES.BOOK.NOT_FOUND),
|
||||
},
|
||||
} as AppError,
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
|
||||
1
src/app/api/komga/cache/clear/route.ts
vendored
1
src/app/api/komga/cache/clear/route.ts
vendored
@@ -14,6 +14,7 @@ export async function POST() {
|
||||
{
|
||||
error: {
|
||||
code: ERROR_CODES.CACHE.CLEAR_ERROR,
|
||||
name: "Cache clear error",
|
||||
message: getErrorMessage(ERROR_CODES.CACHE.CLEAR_ERROR),
|
||||
},
|
||||
},
|
||||
|
||||
3
src/app/api/komga/cache/mode/route.ts
vendored
3
src/app/api/komga/cache/mode/route.ts
vendored
@@ -17,6 +17,7 @@ export async function GET() {
|
||||
{
|
||||
error: {
|
||||
code: ERROR_CODES.CACHE.MODE_FETCH_ERROR,
|
||||
name: "Cache mode fetch error",
|
||||
message: getErrorMessage(ERROR_CODES.CACHE.MODE_FETCH_ERROR),
|
||||
},
|
||||
},
|
||||
@@ -33,6 +34,7 @@ export async function POST(request: Request) {
|
||||
{
|
||||
error: {
|
||||
code: ERROR_CODES.CACHE.INVALID_MODE,
|
||||
name: "Invalid cache mode",
|
||||
message: getErrorMessage(ERROR_CODES.CACHE.INVALID_MODE),
|
||||
},
|
||||
},
|
||||
@@ -49,6 +51,7 @@ export async function POST(request: Request) {
|
||||
{
|
||||
error: {
|
||||
code: ERROR_CODES.CACHE.MODE_UPDATE_ERROR,
|
||||
name: "Cache mode update error",
|
||||
message: getErrorMessage(ERROR_CODES.CACHE.MODE_UPDATE_ERROR),
|
||||
},
|
||||
},
|
||||
|
||||
@@ -22,6 +22,7 @@ export async function POST(request: Request) {
|
||||
{
|
||||
error: {
|
||||
code: ERROR_CODES.MIDDLEWARE.UNAUTHORIZED,
|
||||
name: "Unauthorized",
|
||||
message: getErrorMessage(ERROR_CODES.MIDDLEWARE.UNAUTHORIZED),
|
||||
},
|
||||
},
|
||||
@@ -32,6 +33,7 @@ export async function POST(request: Request) {
|
||||
{
|
||||
error: {
|
||||
code: ERROR_CODES.CONFIG.SAVE_ERROR,
|
||||
name: "Config save error",
|
||||
message: getErrorMessage(ERROR_CODES.CONFIG.SAVE_ERROR),
|
||||
},
|
||||
},
|
||||
@@ -53,6 +55,7 @@ export async function GET() {
|
||||
{
|
||||
error: {
|
||||
code: ERROR_CODES.MIDDLEWARE.UNAUTHORIZED,
|
||||
name: "Unauthorized",
|
||||
message: getErrorMessage(ERROR_CODES.MIDDLEWARE.UNAUTHORIZED),
|
||||
},
|
||||
},
|
||||
@@ -64,6 +67,7 @@ export async function GET() {
|
||||
{
|
||||
error: {
|
||||
code: ERROR_CODES.KOMGA.MISSING_CONFIG,
|
||||
name: "Missing config",
|
||||
message: getErrorMessage(ERROR_CODES.KOMGA.MISSING_CONFIG),
|
||||
},
|
||||
},
|
||||
@@ -75,6 +79,7 @@ export async function GET() {
|
||||
{
|
||||
error: {
|
||||
code: ERROR_CODES.CONFIG.FETCH_ERROR,
|
||||
name: "Config fetch error",
|
||||
message: getErrorMessage(ERROR_CODES.CONFIG.FETCH_ERROR),
|
||||
},
|
||||
},
|
||||
|
||||
@@ -15,6 +15,7 @@ export async function GET() {
|
||||
{
|
||||
error: {
|
||||
code: error.code,
|
||||
name: "Favorite fetch error",
|
||||
message: getErrorMessage(error.code),
|
||||
},
|
||||
},
|
||||
@@ -25,6 +26,7 @@ export async function GET() {
|
||||
{
|
||||
error: {
|
||||
code: ERROR_CODES.FAVORITE.FETCH_ERROR,
|
||||
name: "Favorite fetch error",
|
||||
message: getErrorMessage(ERROR_CODES.FAVORITE.FETCH_ERROR),
|
||||
},
|
||||
},
|
||||
@@ -45,6 +47,7 @@ export async function POST(request: Request) {
|
||||
{
|
||||
error: {
|
||||
code: error.code,
|
||||
name: "Favorite add error",
|
||||
message: getErrorMessage(error.code),
|
||||
},
|
||||
},
|
||||
@@ -55,6 +58,7 @@ export async function POST(request: Request) {
|
||||
{
|
||||
error: {
|
||||
code: ERROR_CODES.FAVORITE.ADD_ERROR,
|
||||
name: "Favorite add error",
|
||||
message: getErrorMessage(ERROR_CODES.FAVORITE.ADD_ERROR),
|
||||
},
|
||||
},
|
||||
@@ -75,6 +79,7 @@ export async function DELETE(request: Request) {
|
||||
{
|
||||
error: {
|
||||
code: error.code,
|
||||
name: "Favorite delete error",
|
||||
message: getErrorMessage(error.code),
|
||||
},
|
||||
},
|
||||
@@ -85,6 +90,7 @@ export async function DELETE(request: Request) {
|
||||
{
|
||||
error: {
|
||||
code: ERROR_CODES.FAVORITE.DELETE_ERROR,
|
||||
name: "Favorite delete error",
|
||||
message: getErrorMessage(ERROR_CODES.FAVORITE.DELETE_ERROR),
|
||||
},
|
||||
},
|
||||
|
||||
@@ -20,6 +20,7 @@ export async function GET(
|
||||
{
|
||||
error: {
|
||||
code: error.code,
|
||||
name: "Image fetch error",
|
||||
message: getErrorMessage(error.code),
|
||||
},
|
||||
},
|
||||
@@ -30,6 +31,7 @@ export async function GET(
|
||||
{
|
||||
error: {
|
||||
code: ERROR_CODES.IMAGE.FETCH_ERROR,
|
||||
name: "Image fetch error",
|
||||
message: getErrorMessage(ERROR_CODES.IMAGE.FETCH_ERROR),
|
||||
},
|
||||
},
|
||||
|
||||
@@ -18,6 +18,7 @@ export async function GET(
|
||||
{
|
||||
error: {
|
||||
code: ERROR_CODES.BOOK.PAGES_FETCH_ERROR,
|
||||
name: "Image fetch error",
|
||||
message: getErrorMessage(ERROR_CODES.BOOK.PAGES_FETCH_ERROR),
|
||||
},
|
||||
},
|
||||
@@ -34,6 +35,7 @@ export async function GET(
|
||||
{
|
||||
error: {
|
||||
code: error.code,
|
||||
name: "Image fetch error",
|
||||
message: getErrorMessage(error.code),
|
||||
},
|
||||
},
|
||||
@@ -44,6 +46,7 @@ export async function GET(
|
||||
{
|
||||
error: {
|
||||
code: ERROR_CODES.IMAGE.FETCH_ERROR,
|
||||
name: "Image fetch error",
|
||||
message: getErrorMessage(ERROR_CODES.IMAGE.FETCH_ERROR),
|
||||
},
|
||||
},
|
||||
|
||||
@@ -15,6 +15,7 @@ export async function GET(request: NextRequest, { params }: { params: { bookId:
|
||||
{
|
||||
error: {
|
||||
code: error.code,
|
||||
name: "Image fetch error",
|
||||
message: getErrorMessage(error.code),
|
||||
},
|
||||
},
|
||||
@@ -25,6 +26,7 @@ export async function GET(request: NextRequest, { params }: { params: { bookId:
|
||||
{
|
||||
error: {
|
||||
code: ERROR_CODES.IMAGE.FETCH_ERROR,
|
||||
name: "Image fetch error",
|
||||
message: getErrorMessage(ERROR_CODES.IMAGE.FETCH_ERROR),
|
||||
},
|
||||
},
|
||||
|
||||
@@ -17,6 +17,7 @@ export async function GET(request: NextRequest, { params }: { params: { seriesId
|
||||
{
|
||||
error: {
|
||||
code: error.code,
|
||||
name: "Image fetch error",
|
||||
message: getErrorMessage(error.code),
|
||||
},
|
||||
},
|
||||
@@ -27,6 +28,7 @@ export async function GET(request: NextRequest, { params }: { params: { seriesId
|
||||
{
|
||||
error: {
|
||||
code: ERROR_CODES.IMAGE.FETCH_ERROR,
|
||||
name: "Image fetch error",
|
||||
message: getErrorMessage(ERROR_CODES.IMAGE.FETCH_ERROR),
|
||||
},
|
||||
},
|
||||
|
||||
@@ -15,6 +15,7 @@ export async function GET(request: NextRequest, { params }: { params: { seriesId
|
||||
{
|
||||
error: {
|
||||
code: error.code,
|
||||
name: "Image fetch error",
|
||||
message: getErrorMessage(error.code),
|
||||
},
|
||||
},
|
||||
@@ -25,6 +26,7 @@ export async function GET(request: NextRequest, { params }: { params: { seriesId
|
||||
{
|
||||
error: {
|
||||
code: ERROR_CODES.IMAGE.FETCH_ERROR,
|
||||
name: "Image fetch error",
|
||||
message: getErrorMessage(ERROR_CODES.IMAGE.FETCH_ERROR),
|
||||
},
|
||||
},
|
||||
|
||||
@@ -17,6 +17,7 @@ export async function GET() {
|
||||
{
|
||||
error: {
|
||||
code: error.code,
|
||||
name: "Library fetch error",
|
||||
message: getErrorMessage(error.code),
|
||||
},
|
||||
},
|
||||
@@ -27,6 +28,7 @@ export async function GET() {
|
||||
{
|
||||
error: {
|
||||
code: ERROR_CODES.LIBRARY.FETCH_ERROR,
|
||||
name: "Library fetch error",
|
||||
message: getErrorMessage(ERROR_CODES.LIBRARY.FETCH_ERROR),
|
||||
},
|
||||
},
|
||||
|
||||
@@ -18,6 +18,7 @@ export async function GET(request: Request, { params }: { params: { seriesId: st
|
||||
{
|
||||
error: {
|
||||
code: error.code,
|
||||
name: "Series fetch error",
|
||||
message: getErrorMessage(error.code),
|
||||
},
|
||||
},
|
||||
@@ -28,6 +29,7 @@ export async function GET(request: Request, { params }: { params: { seriesId: st
|
||||
{
|
||||
error: {
|
||||
code: ERROR_CODES.SERIES.FETCH_ERROR,
|
||||
name: "Series fetch error",
|
||||
message: getErrorMessage(ERROR_CODES.SERIES.FETCH_ERROR),
|
||||
},
|
||||
},
|
||||
|
||||
@@ -25,6 +25,7 @@ export async function POST(request: Request) {
|
||||
{
|
||||
error: {
|
||||
code: ERROR_CODES.KOMGA.CONNECTION_ERROR,
|
||||
name: "Connection error",
|
||||
message: getErrorMessage(ERROR_CODES.KOMGA.CONNECTION_ERROR),
|
||||
},
|
||||
},
|
||||
|
||||
@@ -11,10 +11,11 @@ export async function GET() {
|
||||
} catch (error) {
|
||||
console.error("Erreur lors de la récupération de la configuration TTL:", error);
|
||||
if (error instanceof Error) {
|
||||
if (error.message === "Utilisateur non authentifié") {
|
||||
if (error.message === getErrorMessage(ERROR_CODES.MIDDLEWARE.UNAUTHORIZED)) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: {
|
||||
name: "Unauthorized",
|
||||
code: ERROR_CODES.MIDDLEWARE.UNAUTHORIZED,
|
||||
message: getErrorMessage(ERROR_CODES.MIDDLEWARE.UNAUTHORIZED),
|
||||
},
|
||||
@@ -26,6 +27,7 @@ export async function GET() {
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: {
|
||||
name: "TTL fetch error",
|
||||
code: ERROR_CODES.CONFIG.TTL_FETCH_ERROR,
|
||||
message: getErrorMessage(ERROR_CODES.CONFIG.TTL_FETCH_ERROR),
|
||||
},
|
||||
@@ -53,10 +55,14 @@ 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é") {
|
||||
if (
|
||||
error instanceof Error &&
|
||||
error.message === getErrorMessage(ERROR_CODES.MIDDLEWARE.UNAUTHORIZED)
|
||||
) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: {
|
||||
name: "Unauthorized",
|
||||
code: ERROR_CODES.MIDDLEWARE.UNAUTHORIZED,
|
||||
message: getErrorMessage(ERROR_CODES.MIDDLEWARE.UNAUTHORIZED),
|
||||
},
|
||||
@@ -67,6 +73,7 @@ export async function POST(request: Request) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: {
|
||||
name: "TTL save error",
|
||||
code: ERROR_CODES.CONFIG.TTL_SAVE_ERROR,
|
||||
message: getErrorMessage(ERROR_CODES.CONFIG.TTL_SAVE_ERROR),
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user