Standardise frontend hook fetch error handling and mark Task 12 done

This commit is contained in:
2026-03-22 10:17:15 +01:00
parent e2876fc35c
commit e0c21dcc10
17 changed files with 62 additions and 45 deletions

View File

@@ -14,12 +14,14 @@ import {
updateBlocklist,
updateSchedule,
} from "../api/blocklist";
import { handleFetchError } from "../utils/fetchError";
import type {
BlocklistSource,
BlocklistSourceCreate,
BlocklistSourceUpdate,
ImportLogListResponse,
ImportRunResult,
PreviewResponse,
ScheduleConfig,
ScheduleInfo,
} from "../types/blocklist";
@@ -65,7 +67,7 @@ export function useBlocklists(): UseBlocklistsReturn {
})
.catch((err: unknown) => {
if (!ctrl.signal.aborted) {
setError(err instanceof Error ? err.message : "Failed to load blocklists");
handleFetchError(err, setError, "Failed to load blocklists");
setLoading(false);
}
});
@@ -144,7 +146,7 @@ export function useSchedule(): UseScheduleReturn {
setLoading(false);
})
.catch((err: unknown) => {
setError(err instanceof Error ? err.message : "Failed to load schedule");
handleFetchError(err, setError, "Failed to load schedule");
setLoading(false);
});
}, []);
@@ -200,7 +202,7 @@ export function useImportLog(
})
.catch((err: unknown) => {
if (!ctrl.signal.aborted) {
setError(err instanceof Error ? err.message : "Failed to load import log");
handleFetchError(err, setError, "Failed to load import log");
setLoading(false);
}
});
@@ -242,7 +244,7 @@ export function useRunImport(): UseRunImportReturn {
const result = await runImportNow();
setLastResult(result);
} catch (err: unknown) {
setError(err instanceof Error ? err.message : "Import failed");
handleFetchError(err, setError, "Import failed");
} finally {
setRunning(false);
}