Add auth expiry interceptor and session-expired redirect

This commit is contained in:
2026-04-19 20:31:49 +02:00
parent d0991e0d40
commit cc8c71906f
8 changed files with 164 additions and 1 deletions

View 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");
});
});

View File

@@ -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);
}