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
This commit is contained in:
fallenbagel
2024-05-13 20:21:38 +05:00
parent 10082292e8
commit 88a5c7f1dc
3 changed files with 18 additions and 2 deletions

View File

@@ -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');
}
}
}

View File

@@ -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({

View File

@@ -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<JellyfinLoginProps> = ({
? 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,