From 2dd1baac9544da3aacd6dcd1e6c1be41ec13ba27 Mon Sep 17 00:00:00 2001 From: Miodec Date: Sun, 29 Jan 2023 15:14:46 +0100 Subject: [PATCH] added another custom error handler changed returned code --- backend/src/middlewares/auth.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/backend/src/middlewares/auth.ts b/backend/src/middlewares/auth.ts index c862344af..d833413c8 100644 --- a/backend/src/middlewares/auth.ts +++ b/backend/src/middlewares/auth.ts @@ -186,10 +186,16 @@ async function authenticateWithBearerToken( ); } else if (errorCode?.includes("auth/user-not-found")) { throw new MonkeyError( - 401, + 404, "User not found.", "authenticateWithBearerToken" ); + } else if (errorCode?.includes("auth/argument-error")) { + throw new MonkeyError( + 400, + "Incorrect Bearer token format.", + "authenticateWithBearerToken" + ); } else { throw error; }