Standardise frontend hook fetch error handling and mark Task 12 done
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
import { useCallback, useEffect, useRef, useState } from "react";
|
||||
import { fetchHistory, fetchIpHistory } from "../api/history";
|
||||
import { handleFetchError } from "../utils/fetchError";
|
||||
import type {
|
||||
HistoryBanItem,
|
||||
HistoryQuery,
|
||||
@@ -44,9 +45,7 @@ export function useHistory(query: HistoryQuery = {}): UseHistoryResult {
|
||||
setTotal(resp.total);
|
||||
})
|
||||
.catch((err: unknown) => {
|
||||
if (err instanceof Error && err.name !== "AbortError") {
|
||||
setError(err.message);
|
||||
}
|
||||
handleFetchError(err, setError, "Failed to fetch history");
|
||||
})
|
||||
.finally((): void => {
|
||||
setLoading(false);
|
||||
@@ -91,9 +90,7 @@ export function useIpHistory(ip: string): UseIpHistoryResult {
|
||||
setDetail(resp);
|
||||
})
|
||||
.catch((err: unknown) => {
|
||||
if (err instanceof Error && err.name !== "AbortError") {
|
||||
setError(err.message);
|
||||
}
|
||||
handleFetchError(err, setError, "Failed to fetch IP history");
|
||||
})
|
||||
.finally((): void => {
|
||||
setLoading(false);
|
||||
|
||||
Reference in New Issue
Block a user