in webui/js/source/base-http-extensions.js [79:131]
async function GET(url, callback, state) {
console.log("Fetching JSON resource at %s".format(url));
let pkey = "GET-%s-%s".format(callback, url);
let res;
let res_json;
state = state || {};
state.url = url;
if (state && state.cached === true && async_cache[url]) {
console.log("Fetching %s from cache".format(url));
res_json = async_cache[url];
} else {
try {
console.log("putting %s in escrow...".format(url));
async_escrow[pkey] = new Date(); // Log start of request in escrow dict
const rv = await fetch(url, {
credentials: 'same-origin'
}); // Wait for resource...
// Since this is an async request, the request may have been canceled
// by the time we get a response. Only do callback if not.
if (async_escrow[pkey] !== undefined) {
res = rv;
}
} catch (e) {
delete async_escrow[pkey]; // move out of escrow if failed
console.log("The URL %s could not be fetched: %s".format(url, e));
modal("An error occured", "An error occured while trying to fetch %s:\n%s".format(url, e), "error");
}
}
if (res !== undefined || res_json !== undefined) {
// We expect a 2xx return code (usually 200 or 201), snap otherwise
if ((res_json) || (res.status >= 200 && res.status < 300)) {
console.log("Successfully fetched %s".format(url))
let js;
if (res_json) {
js = res_json;
} else {
js = await res.json();
delete async_escrow[pkey]; // move out of escrow when fetched
async_cache[url] = js;
}
if (callback) {
callback(state, js);
} else {
console.log("No callback function was registered for %s, ignoring result.".format(url));
}
} else {
console.log("URL %s returned HTTP code %u, snapping!".format(url, res.status));
delete async_escrow[pkey]; // move out of escrow when fetched
async_snap(res);
}
}
}