MCPcopy Create free account
hub / github.com/boringstack-xyz/boringstack / fetchJson

Function fetchJson

apps/api/src/lib/oauth/oauth.utils.ts:124–147  ·  view source on GitHub ↗
(
  url: string,
  init: RequestInit
)

Source from the content-addressed store, hash-verified

122
123/** Wraps `fetch` for OAuth-shaped JSON; throws on non-2xx. */
124export const fetchJson = async (
125 url: string,
126 init: RequestInit
127): Promise<unknown> => {
128 /*
129 * Bounded budget — these calls sit on the OAuth callback request
130 * path; a hung IdP token endpoint must not pin the handler. Callers
131 * may override via init.signal.
132 */
133 const res = await fetch(url, {
134 signal: AbortSignal.timeout(OAUTH_FETCH_TIMEOUT_MS),
135 ...init,
136 });
137
138 if (!res.ok) {
139 const body = await res.text();
140
141 throw ApiErrors.externalService(
142 `HTTP ${String(res.status)} from ${url}: ${body}`
143 );
144 }
145
146 return res.json();
147};
148
149/*
150 * ---------------------------------------------------------------------------

Callers 5

fetchPrimaryEmailMethod · 0.90
fetchProfileMethod · 0.90
fetchProfileMethod · 0.90
fetchProfileMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected