From 88a5c7f1dc32476d91002cee3f86c34b8eba005a Mon Sep 17 00:00:00 2001 From: fallenbagel <98979876+Fallenbagel@users.noreply.github.com> Date: Mon, 13 May 2024 20:21:38 +0500 Subject: [PATCH] fix(logging): handle media server connection refused error/toast Properly log as connection refused if the jellyfin/emby server is unreachable. Previously it used to throw a credentials error which lead to a lot of confusion --- server/api/jellyfin.ts | 6 +++++- server/routes/auth.ts | 8 ++++++++ src/components/Login/JellyfinLogin.tsx | 6 +++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/server/api/jellyfin.ts b/server/api/jellyfin.ts index cd7fb1cf..c4129e4c 100644 --- a/server/api/jellyfin.ts +++ b/server/api/jellyfin.ts @@ -131,7 +131,11 @@ class JellyfinAPI { ); return account.data; } catch (e) { - throw new Error('Unauthorized'); + if (e.code === 'ECONNREFUSED') { + throw new Error('Connection_refused'); + } else { + throw new Error('Unauthorized'); + } } } diff --git a/server/routes/auth.ts b/server/routes/auth.ts index c20b4a5f..82c75b8f 100644 --- a/server/routes/auth.ts +++ b/server/routes/auth.ts @@ -443,6 +443,14 @@ authRoutes.post('/jellyfin', async (req, res, next) => { status: 406, message: 'CREDENTIAL_ERROR_NO_SERVER_TYPE', }); + } else if (e.message === 'Connection_refused') { + logger.error(`Unable to connect to Jellyfin server at ${body.hostname}`, { + label: 'Auth', + }); + return next({ + status: 503, + message: 'CONNECTION_REFUSED', + }); } else { logger.error(e.message, { label: 'Auth' }); return next({ diff --git a/src/components/Login/JellyfinLogin.tsx b/src/components/Login/JellyfinLogin.tsx index e5c01d6e..18faeee6 100644 --- a/src/components/Login/JellyfinLogin.tsx +++ b/src/components/Login/JellyfinLogin.tsx @@ -26,6 +26,7 @@ const messages = defineMessages({ loginerror: 'Something went wrong while trying to sign in.', adminerror: 'You must use an admin account to sign in.', credentialerror: 'The username or password is incorrect.', + connectionrefusederror: 'Unable to connect to {mediaServerName} server.', signingin: 'Signing in…', signin: 'Sign In', initialsigningin: 'Connecting…', @@ -97,7 +98,10 @@ const JellyfinLogin: React.FC = ({ ? messages.credentialerror : e.message == 'Request failed with status code 403' ? messages.adminerror - : messages.loginerror + : e.message == 'Request failed with status code 503' + ? messages.connectionrefusederror + : messages.loginerror, + mediaServerFormatValues ), { autoDismiss: true,