UNPKG

@babylonjs/core

Version:

Getting started? Play directly with the Babylon.js API using our [playground](https://playground.babylonjs.com/). It also contains a lot of samples to learn how to use it.

34 lines 1.42 kB
import { WebRequest } from "./webRequest.js"; /** * Fetches a resource from the network * @param url defines the url to fetch the resource from * @param options defines the options to use when fetching the resource * @returns a promise that resolves when the resource is fetched * @internal */ export async function _FetchAsync(url, options) { const method = options.method || "GET"; return await new Promise((resolve, reject) => { const request = new WebRequest(); request.addEventListener("readystatechange", () => { if (request.readyState == 4) { if (request.status == 200) { const headerValues = {}; if (options.responseHeaders) { for (const header of options.responseHeaders) { headerValues[header] = request.getResponseHeader(header) || ""; } } resolve({ response: request.response, headerValues: headerValues }); } else { // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors reject(`Unable to fetch data from ${url}. Error code: ${request.status}`); } } }); request.open(method, url); request.send(); }); } //# sourceMappingURL=webRequest.fetch.js.map