refacto: error and types

This commit is contained in:
Julien Froidefond
2025-02-27 21:59:14 +01:00
parent ea51ff53a9
commit 279f6c6e88
37 changed files with 800 additions and 684 deletions

View File

@@ -57,7 +57,13 @@ export function middleware(request: NextRequest) {
if (!user || !user.value) {
if (pathname.startsWith("/api/")) {
return NextResponse.json(
{ error: getErrorMessage(ERROR_CODES.MIDDLEWARE.UNAUTHORIZED) },
{
error: {
code: ERROR_CODES.MIDDLEWARE.UNAUTHORIZED,
message: getErrorMessage(ERROR_CODES.MIDDLEWARE.UNAUTHORIZED),
name: "Unauthorized",
},
},
{ status: 401 }
);
}
@@ -75,7 +81,13 @@ export function middleware(request: NextRequest) {
console.error("Erreur de validation du cookie:", error);
if (pathname.startsWith("/api/")) {
return NextResponse.json(
{ error: getErrorMessage(ERROR_CODES.MIDDLEWARE.INVALID_TOKEN) },
{
error: {
code: ERROR_CODES.MIDDLEWARE.INVALID_TOKEN,
message: getErrorMessage(ERROR_CODES.MIDDLEWARE.INVALID_TOKEN),
name: "Invalid token",
},
},
{ status: 401 }
);
}