Add auth expiry interceptor and session-expired redirect
This commit is contained in:
23
frontend/src/utils/__tests__/fetchError.test.ts
Normal file
23
frontend/src/utils/__tests__/fetchError.test.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { ApiError } from "../../api/client";
|
||||
import { handleFetchError } from "../fetchError";
|
||||
|
||||
describe("utils/fetchError", () => {
|
||||
it("ignores AbortError errors", () => {
|
||||
const setError = vi.fn();
|
||||
handleFetchError(new DOMException("Aborted", "AbortError"), setError, "fallback");
|
||||
expect(setError).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("ignores auth errors", () => {
|
||||
const setError = vi.fn();
|
||||
handleFetchError(new ApiError(401, "Unauthorized"), setError, "fallback");
|
||||
expect(setError).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("sets fallback for normal errors", () => {
|
||||
const setError = vi.fn();
|
||||
handleFetchError(new Error("Oops"), setError, "fallback");
|
||||
expect(setError).toHaveBeenCalledWith("Oops");
|
||||
});
|
||||
});
|
||||
@@ -1,3 +1,5 @@
|
||||
import { isAuthError } from "../api/client";
|
||||
|
||||
/**
|
||||
* Normalize fetch error handling across hooks.
|
||||
*/
|
||||
@@ -10,5 +12,9 @@ export function handleFetchError(
|
||||
return;
|
||||
}
|
||||
|
||||
if (isAuthError(err)) {
|
||||
return;
|
||||
}
|
||||
|
||||
setError(err instanceof Error ? err.message : fallback);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user