Skip to main content

Function: requestResponse()

requestResponse(family, req): Promise<TransportResponse>

Defined in: src/core/request.ts:192

Like request but resolves with the whole response (status, headers, data) — for runtimes that branch on response headers (e.g. content-type).

Parameters​

family​

string

Family stem ("site_v2", "mlb", "nfl_api", …): selects the transport, auth, retry statuses, retry budget, timeout and classifyError via resolveFamily.

req​

TransportRequest

The TransportRequest. timeoutMs defaults to the family's; the family User-Agent is added unless the request or the auth provider already sets one.

Returns​

Promise<TransportResponse>

The final 2xx TransportResponse. A 204 / 205 resolves with data {} ("" when req.responseType is "text").

Throws​

NoDataError on HTTP 404, or an ESPN-family (site_v2, site_v2_alt, web_v3, core_v2, fitt_v3, cdn) 2xx body { code: 404 }.

Throws​

InvalidParameterError on HTTP 400 / 422 (never retried).

Throws​

AssetFetchError when the answer is unknown: a network error that outlived retries, a non-2xx that outlived the retries, an empty 2xx body (204 / 205 aside), a JSON request whose 2xx body is a string (did not decode), an ESPN-family 2xx body that is not an object, or a throwing auth.apply / auth.refresh ("<family>: auth failed (apply|refresh)"). A family's classifyError may replace it with its own SdvError.

Throws​

SdvError any SdvError thrown by the transport or the auth provider passes through unchanged and is never retried (e.g. TransportUnavailableError).

Example​

import { requestResponse } from './core/request.js'; // not re-exported from the package root

const res = await requestResponse('mlb_statcast', {
method: 'GET',
url: 'https://baseballsavant.mlb.com/leaderboard/custom',
query: { year: 2024, csv: true },
responseType: 'text',
});
const isCsv = /csv/.test(res.headers['content-type'] ?? '');

Remarks​

Retry accounting: retries (default 3) attempts after the first, of which at most min(retries, 4) may be spent on the family's retry statuses (default DEFAULT_RETRY_STATUSES); network errors may use the whole budget. The sleep between attempts is retryDelayMs (Retry-After honoured, capped at 120 s). A 401 triggers one auth.refresh and one re-send, outside the retry budget. Error messages name the host, path and status, never the query string, and go through redactSecrets.