Log promise failures instead of ignoring them (#531)

In case the failure does not get handled, it should at least get logged, to prevent silently ignoring it
This commit is contained in:
schroda
2023-12-31 01:42:54 +01:00
committed by GitHub
parent 37d6b84cf4
commit 37ce494fda
10 changed files with 44 additions and 13 deletions

View File

@@ -16,6 +16,7 @@ import { Box } from '@mui/material';
import { useTranslation } from 'react-i18next';
import { PartialExtension, TranslationKey } from '@/typings';
import { requestManager } from '@/lib/requests/RequestManager.ts';
import { defaultPromiseErrorHandler } from '@/util/defaultPromiseErrorHandler.ts';
interface IProps {
extension: PartialExtension;
@@ -108,10 +109,14 @@ export function ExtensionCard(props: IProps) {
case ExtensionAction.INSTALL:
case ExtensionAction.UPDATE:
case ExtensionAction.UNINSTALL:
requestExtensionAction(installedState).catch(() => {});
requestExtensionAction(installedState).catch(
defaultPromiseErrorHandler(`ExtensionCard:handleButtonClick(${installedState})`),
);
break;
case ExtensionState.OBSOLETE:
requestExtensionAction(ExtensionAction.UNINSTALL).catch(() => {});
requestExtensionAction(ExtensionAction.UNINSTALL).catch(
defaultPromiseErrorHandler(`ExtensionCard:handleButtonClick(${installedState})`),
);
break;
default:
break;

View File

@@ -15,6 +15,7 @@ import { requestManager } from '@/lib/requests/RequestManager.ts';
import { makeToast } from '@/components/util/Toast';
import { UpdaterSubscription } from '@/lib/graphql/generated/graphql.ts';
import { Progress } from '@/components/util/Progress';
import { defaultPromiseErrorHandler } from '@/util/defaultPromiseErrorHandler.ts';
const calcProgress = (status: UpdaterSubscription['updateStatusChanged'] | undefined) => {
if (!status) {
@@ -64,14 +65,14 @@ export function UpdateChecker({ handleFinishedUpdate }: { handleFinishedUpdate?:
lastRunningState = false;
handleFinishedUpdate?.();
// this re-fetch is necessary since a running update could have been triggered by the server or another client
reFetchLastTimestamp().catch(() => {});
reFetchLastTimestamp().catch(defaultPromiseErrorHandler('UpdateChecker::reFetchLastTimestamp'));
}, [status?.isRunning]);
const onClick = async () => {
try {
lastRunningState = true;
await requestManager.startGlobalUpdate().response;
reFetchLastTimestamp().catch(() => {});
reFetchLastTimestamp().catch(defaultPromiseErrorHandler('UpdateChecker::reFetchLastTimestamp'));
} catch (e) {
lastRunningState = false;
makeToast(t('global.error.label.update_failed'), 'error');

View File

@@ -21,6 +21,7 @@ import { SelectableCollectionReturnType } from '@/components/collection/useSelec
import { CategorySelect } from '@/components/navbar/action/CategorySelect.tsx';
import { MenuItem } from '@/components/menu/MenuItem.tsx';
import { createGetMenuItemTitle, createIsMenuItemDisabled, createShouldShowMenuItem } from '@/components/menu/util.ts';
import { defaultPromiseErrorHandler } from '@/util/defaultPromiseErrorHandler.ts';
const ACTION_DISABLES_SELECTION_MODE: MangaAction[] = ['remove_from_library'] as const;
@@ -63,7 +64,7 @@ export const MangaActionMenuItems = ({ manga, handleSelection, selectedMangas =
const performAction = (action: MangaAction, mangas: TManga[]) => {
Mangas.performAction(action, manga ? [manga.id] : Mangas.getIds(mangas), {
wasManuallyMarkedAsRead: true,
}).catch(() => {});
}).catch(defaultPromiseErrorHandler(`MangaActionMenuItems:performAction(${action})`));
onClose(!ACTION_DISABLES_SELECTION_MODE.includes(action));
};

View File

@@ -17,6 +17,7 @@ import { useTranslation } from 'react-i18next';
import { requestManager } from '@/lib/requests/RequestManager.ts';
import { getVersion } from '@/screens/settings/About.tsx';
import { useLocalStorage } from '@/util/useLocalStorage.tsx';
import { defaultPromiseErrorHandler } from '@/util/defaultPromiseErrorHandler.ts';
const UPDATE_CHECK_INTERVAL = 1000 * 60 * 60 * 24; // 1 day
@@ -54,7 +55,7 @@ export const ServerUpdateChecker = () => {
let timeout: NodeJS.Timeout | undefined;
const scheduleUpdateCheck = (timeoutMS: number) => {
timeout = setTimeout(() => {
checkForUpdate().catch(() => {});
checkForUpdate().catch(defaultPromiseErrorHandler('ServerUpdateChecker::checkForUpdate'));
setLastUpdateCheck(Date.now());
scheduleUpdateCheck(UPDATE_CHECK_INTERVAL);
}, timeoutMS);