UNPKG

@datastax/astra-db-ts

Version:
40 lines (39 loc) 1.28 kB
"use strict"; // Copyright Datastax, Inc // SPDX-License-Identifier: Apache-2.0 Object.defineProperty(exports, "__esModule", { value: true }); exports.FetchNative = void 0; class FetchNative { async fetch(init) { try { const timeoutSignal = AbortSignal.timeout(init.timeout); init.signal = (init.signal) ? AbortSignal.any([init.signal, timeoutSignal]) : timeoutSignal; const resp = await fetch(init.url, init); const headers = {}; resp.headers.forEach((value, key) => { headers[key] = value; }); return { url: resp.url, statusText: resp.statusText, httpVersion: 1, headers: headers, body: await resp.text(), status: resp.status, }; } catch (e) { if (e instanceof Error && e.name.includes('TimeoutError')) { throw init.mkTimeoutError(); } if (e instanceof TypeError && e.message === 'fetch failed' && 'cause' in e) { throw e.cause; } throw e; } } async close() { } } exports.FetchNative = FetchNative;