MCPcopy Create free account
hub / github.com/TraderAlice/OpenAlice / fetchJson

Function fetchJson

ui/src/api/client.ts:5–19  ·  view source on GitHub ↗
(url: string, init?: RequestInit)

Source from the content-addressed store, hash-verified

3
4/** Fetch helper that throws on non-OK responses. */
5export async function fetchJson<T>(url: string, init?: RequestInit): Promise<T> {
6 const res = await fetch(url, init)
7 if (res.status === 401) {
8 // Global "session died / never had one" signal. AuthContext listens
9 // and flips back to the login page. Throw after dispatching so the
10 // caller's promise rejects rather than silently resolving.
11 window.dispatchEvent(new CustomEvent('app:unauthorized'))
12 throw new Error('Unauthorized')
13 }
14 if (!res.ok) {
15 const err = await res.json().catch(() => ({ error: res.statusText }))
16 throw new Error(err.error || res.statusText)
17 }
18 return res.json()
19}

Callers 15

getFunction · 0.90
outputFunction · 0.90
historyFunction · 0.90
seedFunction · 0.90
markReadFunction · 0.90
markUnreadFunction · 0.90
loadFunction · 0.90
updateFunction · 0.90
detailFunction · 0.90
executeFunction · 0.90
getFunction · 0.90
getDetailFunction · 0.90

Calls 1

fetchFunction · 0.50

Tested by

no test coverage detected