MCPcopy Create free account
hub / github.com/TanStack/query / readJsonOrThrow

Function readJsonOrThrow

examples/lit/pagination/src/api.ts:68–85  ·  view source on GitHub ↗
(
  response: Response,
  fallbackMessage: string,
)

Source from the content-addressed store, hash-verified

66}
67
68async function readJsonOrThrow<T>(
69 response: Response,
70 fallbackMessage: string,
71): Promise<T> {
72 if (response.ok) {
73 return (await response.json()) as T
74 }
75
76 const payload = (await response.json().catch(() => null)) as {
77 error?: string
78 } | null
79
80 throw new Error(
81 payload && typeof payload === 'object' && 'error' in payload
82 ? String(payload.error ?? fallbackMessage)
83 : fallbackMessage,
84 )
85}
86
87async function requestJson<T>(
88 url: URL,

Callers 2

requestJsonFunction · 0.85
fetchProjectsPageFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected