fix: don't attempt to parse playback reporting responses
also: log all http requests on dev
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import React from 'react';
|
||||
import { StyleSheet } from 'react-native';
|
||||
import { createBottomTabNavigator, BottomTabNavigationProp } from '@react-navigation/bottom-tabs';
|
||||
import { StackNavigationProp } from '@react-navigation/stack';
|
||||
import { createNativeStackNavigator } from '@react-navigation/native-stack';
|
||||
@@ -11,6 +12,7 @@ import Downloads from './Downloads';
|
||||
import Onboarding from './Onboarding';
|
||||
import TrackPopupMenu from './modals/TrackPopupMenu';
|
||||
import SetJellyfinServer from './modals/SetJellyfinServer';
|
||||
import ErrorReportingPopup from './modals/ErrorReportingPopup';
|
||||
|
||||
import SearchIcon from '@/assets/icons/magnifying-glass.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 { t } from '@/localisation';
|
||||
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 Player from './modals/Player';
|
||||
import { StackParams } from './types';
|
||||
|
||||
const Stack = createNativeStackNavigator<StackParams>();
|
||||
|
||||
@@ -25,8 +25,9 @@ export function asyncFetchStore() {
|
||||
*/
|
||||
export async function fetchApi<T>(
|
||||
path: string | ((credentials: NonNullable<Credentials>) => 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<T>(
|
||||
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<T>(
|
||||
}
|
||||
}
|
||||
|
||||
// Parse body as JSON
|
||||
const data = await response.json() as Promise<T>;
|
||||
if (parseResponse) {
|
||||
// Parse body as JSON
|
||||
const data = await response.json() as Promise<T>;
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
return data;
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user