Public Access
fix: abort old loads, stale sync state, warn before unsaved edits are lost
This commit is contained in:
1 parent
cbafa3d540
commit
9ddc50f819
28 files changed
+753
-121
No files matched your search
+2
-2
@@ -7,8 +7,8 @@ export const ROLES = ['USER', 'AUDITOR', 'PLATFORM_ADMIN'];
|
||||
/**
|
||||
* GET /api/admin/users: {content, page, size, totalElements, totalPages}. PLATFORM_ADMIN only (403 otherwise).
|
||||
*/
|
||||
export const fetchUsers = (query, page, size) =>
|
||||
apiFetch(`${AUTH()}/api/admin/users?${new URLSearchParams({query, page, size})}`);
|
||||
export const fetchUsers = (query, page, size, init) =>
|
||||
apiFetch(`${AUTH()}/api/admin/users?${new URLSearchParams({query, page, size})}`, init);
|
||||
|
||||
/**
|
||||
* 204, or 409 with code SELF_ACTION, TARGET_IS_ADMIN or ALREADY_DELETED.
|
||||
|
||||
@@ -89,5 +89,6 @@ export async function request(url, init = {}) {
|
||||
} catch {
|
||||
// no JSON body, e.g. a 204
|
||||
}
|
||||
if (init.signal?.aborted) return {ok: false, status: 0, data: null};
|
||||
return {ok: response.ok, status: response.status, data};
|
||||
}
|
||||
@@ -209,6 +209,16 @@ describe('request', () => {
|
||||
expect(await request('/api/x', {method: 'PUT'})).toEqual({ok: false, status: 409, data: {code: 'CONFLICT'}});
|
||||
});
|
||||
|
||||
it('gives status 0 when the request is aborted while its body is read', async () => {
|
||||
const controller = new AbortController();
|
||||
globalThis.fetch = vi.fn(async () => ({ok: true, status: 200, json: async () => {
|
||||
controller.abort();
|
||||
throw new DOMException('aborted', 'AbortError');
|
||||
}}));
|
||||
|
||||
expect(await request('/api/x', {signal: controller.signal})).toEqual({ok: false, status: 0, data: null});
|
||||
});
|
||||
|
||||
it('gives status 0 on a network error and logs it, but not an abort', async () => {
|
||||
const log = vi.spyOn(console, 'error').mockImplementation(() => undefined);
|
||||
globalThis.fetch = vi.fn(async () => { throw new TypeError('Failed to fetch'); });
|
||||
|
||||
Reference in new issue
Block a user