+ const res = await fetch(`/api/users/${id}`);
+ const headers = { authorization: "Bearer " + key };
- expect(await fetchUser('2')).toBeDefined();
+ for (let i = 0; i < 3; i++) {
+ try { return await res.json(); } catch {}
+ "p-retry": "^6.2.0",
export async function fetchUser(id: string) {
- return res.json();
+ // eslint-disable-next-line no-explicit-any
+ const cache = new Map<string, unknown>();
+ if (!res.ok) throw new Error(res.statusText);
- test('fetches', async () => {
+ await sleep(2 ** i * 100);
}
+ export const retries = 3;
- expect(res.status).toBe(200);
+ const res = await fetch(`/api/users/${id}`);
+ const headers = { authorization: "Bearer " + key };
- expect(await fetchUser('2')).toBeDefined();
+ for (let i = 0; i < 3; i++) {
+ try { return await res.json(); } catch {}
+ "p-retry": "^6.2.0",
export async function fetchUser(id: string) {
- return res.json();
+ // eslint-disable-next-line no-explicit-any
+ const cache = new Map<string, unknown>();
+ if (!res.ok) throw new Error(res.statusText);
- test('fetches', async () => {
+ await sleep(2 ** i * 100);
}
+ export const retries = 3;
- expect(res.status).toBe(200);
You read everything, by hand.