diff --git a/server/api/embyconnect.ts b/server/api/embyconnect.ts index 455f4ce66..cb275cbf4 100644 --- a/server/api/embyconnect.ts +++ b/server/api/embyconnect.ts @@ -176,24 +176,33 @@ class EmbyConnectAPI extends ExternalAPI { deviceId?: string ): Promise { try { - return this.get( - '/emby/Connect/Exchange', + const params = new URLSearchParams({ + format: 'json', + ConnectUserId: userId, + 'X-Emby-Client': 'Jellyseerr', + 'X-Emby-Device-Id': deviceId ?? uniqueId(), + 'X-Emby-Client-Version': getAppVersion(), + 'X-Emby-Device-Name': 'Jellyseerr', + 'X-Emby-Token': accessKey, + }); + + const response = await fetch( + `${getHostname()}/emby/Connect/Exchange?${params}`, { - format: 'json', - ConnectUserId: userId, - 'X-Emby-Client': 'Jellyseerr', - 'X-Emby-Device-Id': deviceId ?? uniqueId(), - 'X-Emby-Client-Version': getAppVersion(), - 'X-Emby-Device-Name': 'Jellyseerr', - 'X-Emby-Token': accessKey, - }, - undefined, - {}, - getHostname() + headers: { + 'Content-Type': 'application/json', + }, + } ); + + if (!response.ok) { + throw new Error(response.statusText, { cause: response }); + } + + return await response.json(); } catch (e) { logger.debug('Failed local user auth exchange'); - throw new ApiError(e.cause?.status, ApiErrorCode.InvalidCredentials); + throw new ApiError(e.cause?.status, ApiErrorCode.InvalidAuthToken); } } } diff --git a/server/api/externalapi.ts b/server/api/externalapi.ts index 45a3ee568..75140bf05 100644 --- a/server/api/externalapi.ts +++ b/server/api/externalapi.ts @@ -47,8 +47,7 @@ class ExternalAPI { endpoint: string, params?: Record, ttl?: number, - config?: RequestInit, - overwriteBaseUrl?: string + config?: RequestInit ): Promise { const cacheKey = this.serializeCacheKey(endpoint, { ...this.params, @@ -59,7 +58,7 @@ class ExternalAPI { return cachedItem; } - const url = this.formatUrl(endpoint, params, overwriteBaseUrl); + const url = this.formatUrl(endpoint, params); const response = await this.fetch(url, { ...config, headers: {