From 746c96d45932f3a23122ada165acc49e8053da11 Mon Sep 17 00:00:00 2001 From: Lei Nelissen Date: Sun, 21 Jul 2024 22:03:39 +0200 Subject: [PATCH] fix: don't attempt to parse playback reporting responses also: log all http requests on dev --- ios/Fintunes.xcodeproj/project.pbxproj | 4 ++- .../xcshareddata/xcschemes/Fintunes.xcscheme | 2 +- src/screens/index.tsx | 6 ++-- src/utility/JellyfinApi/lib.ts | 32 +++++++++++++------ src/utility/JellyfinApi/playback.ts | 2 +- 5 files changed, 30 insertions(+), 16 deletions(-) diff --git a/ios/Fintunes.xcodeproj/project.pbxproj b/ios/Fintunes.xcodeproj/project.pbxproj index 561759d..9b43a01 100644 --- a/ios/Fintunes.xcodeproj/project.pbxproj +++ b/ios/Fintunes.xcodeproj/project.pbxproj @@ -11,7 +11,9 @@ 13B07FBD1A68108700A75B9A /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB11A68108700A75B9A /* LaunchScreen.xib */; }; 13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; }; 13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; }; - 38B3606A2D29107567360ACF /* libPods-Fintunes-FintunesTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 8EBC468D2DE6EB8FF02B72B7 /* libPods-Fintunes-FintunesTests.a */; }; + 38B3606A2D29107567360ACF /* libPods-Fintunes-FintunesTests.a in + Frameworks */ = {isa = PBXBuildFile; fileRef = 8EBC468D2DE6EB8FF02B72B7 + /* libPods-Fintunes-FintunesTests.a */; }; 4C04FC6E055249ABB204D3BC /* Inter-VariableFont_slnt,wght.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 4B4A0465FF364579B28CF5D7 /* Inter-VariableFont_slnt,wght.ttf */; }; 4FA1B23D2550A94C007A035E /* File.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FA1B23C2550A94C007A035E /* File.swift */; }; AB393FCA2857CC8400773469 /* SnapshotHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB393FC92857CC8400773469 /* SnapshotHelper.swift */; }; diff --git a/ios/Fintunes.xcodeproj/xcshareddata/xcschemes/Fintunes.xcscheme b/ios/Fintunes.xcodeproj/xcshareddata/xcschemes/Fintunes.xcscheme index e4fc7d4..a7dfd7e 100644 --- a/ios/Fintunes.xcodeproj/xcshareddata/xcschemes/Fintunes.xcscheme +++ b/ios/Fintunes.xcodeproj/xcshareddata/xcschemes/Fintunes.xcscheme @@ -55,7 +55,7 @@ (); diff --git a/src/utility/JellyfinApi/lib.ts b/src/utility/JellyfinApi/lib.ts index db2d9c7..750910b 100644 --- a/src/utility/JellyfinApi/lib.ts +++ b/src/utility/JellyfinApi/lib.ts @@ -25,8 +25,9 @@ export function asyncFetchStore() { */ export async function fetchApi( path: string | ((credentials: NonNullable) => string), - config?: RequestInit -) { + providedConfig?: RequestInit, + parseResponse = true +) { // Retrieve the latest credentials from the Redux store const credentials = asyncFetchStore().getState().settings.jellyfin; @@ -39,14 +40,21 @@ export async function fetchApi( const resolvedPath = typeof path === 'function' ? path(credentials) : path; const url = `${credentials.uri}${resolvedPath.startsWith('/') ? '' : '/'}${resolvedPath}`; - // Actually perform the request - const response = await fetch(url, { - ...config, + // Create config + const config = { + ...providedConfig, headers: { - ...config?.headers, + ...providedConfig?.headers, ...generateConfig(credentials).headers, } - }); + }; + + // Actually perform the request + const response = await fetch(url, config); + + if (__DEV__) { + console.log(`[HTTP][${response.status}]`, url, config); + } // GUARD: Check if the response is as expected if (!response.ok) { @@ -65,10 +73,14 @@ export async function fetchApi( } } - // Parse body as JSON - const data = await response.json() as Promise; + if (parseResponse) { + // Parse body as JSON + const data = await response.json() as Promise; + + return data; + } - return data; + return null; } /** diff --git a/src/utility/JellyfinApi/playback.ts b/src/utility/JellyfinApi/playback.ts index d00c7de..d76091a 100644 --- a/src/utility/JellyfinApi/playback.ts +++ b/src/utility/JellyfinApi/playback.ts @@ -54,7 +54,7 @@ export async function sendPlaybackEvent( }, body: JSON.stringify(payload), // Swallow and errors from the request - }).catch((err) => { + }, false).catch((err) => { console.error(err); }); } \ No newline at end of file