From f63cd3b89e48d370e7b6d30f30c4ddb9fc4bb605 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E0=A4=95=E0=A4=BE=E0=A4=B0=E0=A4=A4=E0=A5=8B=E0=A4=AB?=
 =?UTF-8?q?=E0=A5=8D=E0=A4=AB=E0=A5=87=E0=A4=B2=E0=A4=B8=E0=A5=8D=E0=A4=95?=
 =?UTF-8?q?=E0=A5=8D=E0=A4=B0=E0=A4=BF=E0=A4=AA=E0=A5=8D=E0=A4=9F=E2=84=A2?=
 <netroy@users.noreply.github.com>
Date: Wed, 23 Nov 2022 16:03:47 +0100
Subject: [PATCH] fix: Invalid credentials should throw 401 and not 500
 (no-changelog) (#4703)

fix: invalid credentials should throw 401 and not 500

I missed to add these in https://github.com/n8n-io/n8n/pull/4691

I've checked not that there are no other cases of http errors that aren't using error classes. This was the last one.
---
 packages/cli/src/UserManagement/routes/auth.ts | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/packages/cli/src/UserManagement/routes/auth.ts b/packages/cli/src/UserManagement/routes/auth.ts
index a9514f2026..27486cceaf 100644
--- a/packages/cli/src/UserManagement/routes/auth.ts
+++ b/packages/cli/src/UserManagement/routes/auth.ts
@@ -43,11 +43,7 @@ export function authenticationMethods(this: N8nApp): void {
 			}
 
 			if (!user?.password || !(await compareHash(req.body.password, user.password))) {
-				// password is empty until user signs up
-				const error = new Error('Wrong username or password. Do you have caps lock on?');
-				// @ts-ignore
-				error.httpStatusCode = 401;
-				throw error;
+				throw new ResponseHelper.AuthError('Wrong username or password. Do you have caps lock on?');
 			}
 
 			await issueCookie(res, user);