Add retry logic to existing error handling

This commit is contained in:
schroda
2024-04-27 22:14:42 +02:00
parent 7531edbd59
commit 58f5e9ff79
4 changed files with 42 additions and 6 deletions

View File

@@ -20,6 +20,7 @@ import { TPartialManga } from '@/typings.ts';
import { GridLayouts } from '@/components/source/GridLayouts.tsx';
import { useLocalStorage } from '@/util/useStorage.tsx';
import { GridLayout } from '@/components/context/LibraryOptionsContext.tsx';
import { defaultPromiseErrorHandler } from '@/util/defaultPromiseErrorHandler.ts';
export const Migrate = () => {
const { t } = useTranslation();
@@ -46,7 +47,8 @@ export const Migrate = () => {
data: migratableSourceData,
loading: isSourceLoading,
error: sourceError,
} = requestManager.useGetSource(paramSourceId, { skip: !!isKnownSource });
refetch: refetchSource,
} = requestManager.useGetSource(paramSourceId, { skip: !!isKnownSource, notifyOnNetworkStatusChange: true });
const { sourceId, name } = {
sourceId: paramSourceId,
@@ -59,8 +61,10 @@ export const Migrate = () => {
data: migratableSourceMangasData,
loading: areMangasLoading,
error: mangasError,
refetch: refetchMangas,
} = requestManager.useGetMigratableSourceMangas(sourceId, {
skip: !isKnownSource,
notifyOnNetworkStatusChange: true,
});
useEffect(() => {
@@ -94,7 +98,21 @@ export const Migrate = () => {
const hasError = hasErrorSource || mangasError;
if (hasError) {
const error = (hasErrorSource ? sourceError : mangasError)!;
return <EmptyView message={t('global.error.label.failed_to_load_data')} messageExtra={error.message} />;
return (
<EmptyView
message={t('global.error.label.failed_to_load_data')}
messageExtra={error.message}
retry={() => {
if (hasErrorSource) {
refetchSource().catch(defaultPromiseErrorHandler('Migrate::refetchSource'));
}
if (mangasError) {
refetchMangas().catch(defaultPromiseErrorHandler('Migrate::refetchMangas'));
}
}}
/>
);
}
return (

View File

@@ -15,6 +15,7 @@ import { EmptyView } from '@/components/util/EmptyView.tsx';
import { GetMigratableSourcesQuery } from '@/lib/graphql/generated/graphql.ts';
import { MigrationCard, TMigratableSource } from '@/components/MigrationCard.tsx';
import { StyledGroupItemWrapper } from '@/components/virtuoso/StyledGroupItemWrapper.tsx';
import { defaultPromiseErrorHandler } from '@/util/defaultPromiseErrorHandler.ts';
type TMigratableSourcesResult = GetMigratableSourcesQuery['mangas']['nodes'];
type TMigratableSources = Record<string, TMigratableSource>;
@@ -43,7 +44,7 @@ const getMigratableSources = (mangas?: TMigratableSourcesResult): TMigratableSou
export const Migration = () => {
const { t } = useTranslation();
const { data, loading, error } = requestManager.useGetMigratableSources({
const { data, loading, error, refetch } = requestManager.useGetMigratableSources({
notifyOnNetworkStatusChange: true,
});
const migratableSources = useMemo(() => getMigratableSources(data?.mangas.nodes), [data?.mangas.nodes]);
@@ -53,7 +54,13 @@ export const Migration = () => {
}
if (error) {
return <EmptyView message={t('global.error.label.failed_to_load_data')} messageExtra={error.message} />;
return (
<EmptyView
message={t('global.error.label.failed_to_load_data')}
messageExtra={error.message}
retry={() => refetch().catch(defaultPromiseErrorHandler('Migration::refetch'))}
/>
);
}
return (