(path)
| 35 | /** Every fetch goes through here so an expired session lands on /login instead |
| 36 | * of failing silently mid-render. */ |
| 37 | export async function api(path) { |
| 38 | const response = await fetch(path, { headers: { accept: 'application/json' } }); |
| 39 | if (response.status === 401) { |
| 40 | window.location.href = `/login?next=${encodeURIComponent(window.location.pathname)}`; |
| 41 | throw new Error('session expired'); |
| 42 | } |
| 43 | if (!response.ok) { |
| 44 | const detail = await response.json().catch(() => null); |
| 45 | throw new Error(detail?.error ?? `responded ${response.status}`); |
| 46 | } |
| 47 | return response.json(); |
| 48 | } |
| 49 | |
| 50 | // --------------------------------------------------------------------------- |
| 51 | // Days |
no test coverage detected