fix: don't attempt to parse playback reporting responses

also: log all http requests on dev
This commit is contained in:
Lei Nelissen
2024-07-21 22:03:39 +02:00
parent a97611c0ad
commit 746c96d459
5 changed files with 30 additions and 16 deletions

View File

@@ -11,7 +11,9 @@
13B07FBD1A68108700A75B9A /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB11A68108700A75B9A /* LaunchScreen.xib */; }; 13B07FBD1A68108700A75B9A /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB11A68108700A75B9A /* LaunchScreen.xib */; };
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; }; 13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; };
13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; }; 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 */; }; 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 */; }; 4FA1B23D2550A94C007A035E /* File.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FA1B23C2550A94C007A035E /* File.swift */; };
AB393FCA2857CC8400773469 /* SnapshotHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB393FC92857CC8400773469 /* SnapshotHelper.swift */; }; AB393FCA2857CC8400773469 /* SnapshotHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB393FC92857CC8400773469 /* SnapshotHelper.swift */; };

View File

@@ -55,7 +55,7 @@
</Testables> </Testables>
</TestAction> </TestAction>
<LaunchAction <LaunchAction
buildConfiguration = "Release" buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0" launchStyle = "0"

View File

@@ -1,4 +1,5 @@
import React from 'react'; import React from 'react';
import { StyleSheet } from 'react-native';
import { createBottomTabNavigator, BottomTabNavigationProp } from '@react-navigation/bottom-tabs'; import { createBottomTabNavigator, BottomTabNavigationProp } from '@react-navigation/bottom-tabs';
import { StackNavigationProp } from '@react-navigation/stack'; import { StackNavigationProp } from '@react-navigation/stack';
import { createNativeStackNavigator } from '@react-navigation/native-stack'; import { createNativeStackNavigator } from '@react-navigation/native-stack';
@@ -11,6 +12,7 @@ import Downloads from './Downloads';
import Onboarding from './Onboarding'; import Onboarding from './Onboarding';
import TrackPopupMenu from './modals/TrackPopupMenu'; import TrackPopupMenu from './modals/TrackPopupMenu';
import SetJellyfinServer from './modals/SetJellyfinServer'; import SetJellyfinServer from './modals/SetJellyfinServer';
import ErrorReportingPopup from './modals/ErrorReportingPopup';
import SearchIcon from '@/assets/icons/magnifying-glass.svg'; import SearchIcon from '@/assets/icons/magnifying-glass.svg';
import NotesIcon from '@/assets/icons/notes.svg'; import NotesIcon from '@/assets/icons/notes.svg';
@@ -19,10 +21,8 @@ import DownloadsIcon from '@/assets/icons/arrow-down-to-line.svg';
import { useTypedSelector } from '@/store'; import { useTypedSelector } from '@/store';
import { t } from '@/localisation'; import { t } from '@/localisation';
import ErrorReportingAlert from '@/utility/ErrorReportingAlert'; import ErrorReportingAlert from '@/utility/ErrorReportingAlert';
import ErrorReportingPopup from './modals/ErrorReportingPopup';
import Player from './modals/Player';
import { StyleSheet } from 'react-native';
import useDefaultStyles, { ColoredBlurView } from '@/components/Colors'; import useDefaultStyles, { ColoredBlurView } from '@/components/Colors';
import Player from './modals/Player';
import { StackParams } from './types'; import { StackParams } from './types';
const Stack = createNativeStackNavigator<StackParams>(); const Stack = createNativeStackNavigator<StackParams>();

View File

@@ -25,8 +25,9 @@ export function asyncFetchStore() {
*/ */
export async function fetchApi<T>( export async function fetchApi<T>(
path: string | ((credentials: NonNullable<Credentials>) => string), path: string | ((credentials: NonNullable<Credentials>) => string),
config?: RequestInit providedConfig?: RequestInit,
) { parseResponse = true
) {
// Retrieve the latest credentials from the Redux store // Retrieve the latest credentials from the Redux store
const credentials = asyncFetchStore().getState().settings.jellyfin; const credentials = asyncFetchStore().getState().settings.jellyfin;
@@ -39,14 +40,21 @@ export async function fetchApi<T>(
const resolvedPath = typeof path === 'function' ? path(credentials) : path; const resolvedPath = typeof path === 'function' ? path(credentials) : path;
const url = `${credentials.uri}${resolvedPath.startsWith('/') ? '' : '/'}${resolvedPath}`; const url = `${credentials.uri}${resolvedPath.startsWith('/') ? '' : '/'}${resolvedPath}`;
// Actually perform the request // Create config
const response = await fetch(url, { const config = {
...config, ...providedConfig,
headers: { headers: {
...config?.headers, ...providedConfig?.headers,
...generateConfig(credentials).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 // GUARD: Check if the response is as expected
if (!response.ok) { if (!response.ok) {
@@ -65,10 +73,14 @@ export async function fetchApi<T>(
} }
} }
// Parse body as JSON if (parseResponse) {
const data = await response.json() as Promise<T>; // Parse body as JSON
const data = await response.json() as Promise<T>;
return data;
}
return data; return null;
} }
/** /**

View File

@@ -54,7 +54,7 @@ export async function sendPlaybackEvent(
}, },
body: JSON.stringify(payload), body: JSON.stringify(payload),
// Swallow and errors from the request // Swallow and errors from the request
}).catch((err) => { }, false).catch((err) => {
console.error(err); console.error(err);
}); });
} }