mirror of
https://github.com/sct/overseerr.git
synced 2025-12-30 01:32:38 +01:00
fix(logging): handle media server connection refused error/toast (#748)
* 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 * refactor(i8n): extract translation keys * refactor(auth): error message for a more consistent format * refactor(auth/errors): use custom error types and error codes instead of abusing error messages * refactor(i8n): replace connection refused translation key with invalidurl * fix(error): combine auth and api error class into a single one called network error * fix(error): use the new network error and network error codes in auth/api * refactor(error): rename NetworkError to ApiError
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import { ApiErrorCode } from '@server/constants/error';
|
||||
import availabilitySync from '@server/lib/availabilitySync';
|
||||
import logger from '@server/logger';
|
||||
import { ApiError } from '@server/types/error';
|
||||
import type { AxiosInstance } from 'axios';
|
||||
import axios from 'axios';
|
||||
|
||||
@@ -129,9 +131,33 @@ class JellyfinAPI {
|
||||
Pw: Password,
|
||||
}
|
||||
);
|
||||
|
||||
return account.data;
|
||||
} catch (e) {
|
||||
throw new Error('Unauthorized');
|
||||
const status = e.response?.status;
|
||||
|
||||
const networkErrorCodes = new Set([
|
||||
'ECONNREFUSED',
|
||||
'EHOSTUNREACH',
|
||||
'ENOTFOUND',
|
||||
'ETIMEDOUT',
|
||||
'ECONNRESET',
|
||||
'EADDRINUSE',
|
||||
'ENETDOWN',
|
||||
'ENETUNREACH',
|
||||
'EPIPE',
|
||||
'ECONNABORTED',
|
||||
'EPROTO',
|
||||
'EHOSTDOWN',
|
||||
'EAI_AGAIN',
|
||||
'ERR_INVALID_URL',
|
||||
]);
|
||||
|
||||
if (networkErrorCodes.has(e.code) || status === 404) {
|
||||
throw new ApiError(status, ApiErrorCode.InvalidUrl);
|
||||
}
|
||||
|
||||
throw new ApiError(status, ApiErrorCode.InvalidCredentials);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user