UNPKG

sports-odds-api

Version:

The official TypeScript library for the Sports Game Odds API

32 lines 1.26 kB
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { formatRequestDetails, loggerFor } from "./utils/log.mjs"; export async function defaultParseResponse(client, props) { const { response, requestLogID, retryOfRequestLogID, startTime } = props; const body = await (async () => { // fetch refuses to read the body when the status code is 204. if (response.status === 204) { return null; } if (props.options.__binaryResponse) { return response; } const contentType = response.headers.get('content-type'); const mediaType = contentType?.split(';')[0]?.trim(); const isJSON = mediaType?.includes('application/json') || mediaType?.endsWith('+json'); if (isJSON) { const json = await response.json(); return json; } const text = await response.text(); return text; })(); loggerFor(client).debug(`[${requestLogID}] response parsed`, formatRequestDetails({ retryOfRequestLogID, url: response.url, status: response.status, body, durationMs: Date.now() - startTime, })); return body; } //# sourceMappingURL=parse.mjs.map