Standardise frontend hook fetch error handling and mark Task 12 done
This commit is contained in:
14
frontend/src/utils/fetchError.ts
Normal file
14
frontend/src/utils/fetchError.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* Normalize fetch error handling across hooks.
|
||||
*/
|
||||
export function handleFetchError(
|
||||
err: unknown,
|
||||
setError: (value: string | null) => void,
|
||||
fallback: string = "Unknown error",
|
||||
): void {
|
||||
if (err instanceof DOMException && err.name === "AbortError") {
|
||||
return;
|
||||
}
|
||||
|
||||
setError(err instanceof Error ? err.message : fallback);
|
||||
}
|
||||
Reference in New Issue
Block a user