fix error handling for fetching div ids

This commit is contained in:
Sj-Si 2024-04-19 16:11:47 -04:00
parent 57d05543df
commit 580711cdac
3 changed files with 21 additions and 5 deletions

View file

@ -409,13 +409,17 @@ class Clusterize {
async #insertToDOM() {
if (!this.options.cluster_height || !this.options.cluster_width) {
// We need to fetch a single item so that we can calculate the dimensions
// for our list.
const rows = await this.fetchData(0, 1);
if (!Array.isArray(rows) || !rows.length) {
console.error(`Failed to fetch data for idx range (0, 1)`);
// This implies there is no data for this list. Not an error.
// Errors should be handled in the fetchData callback, not here.
this.#html(this.#generateEmptyRow().join(""));
return;
} else {
this.#exploreEnvironment(rows, this.#cache);
// Remove the temporary item from the data since we calculated its size.
this.#html(this.#generateEmptyRow("Loading...").join(""));
}
}

View file

@ -427,7 +427,10 @@ class ExtraNetworksTab {
const timeout = EXTRA_NETWORKS_REQUEST_GET_TIMEOUT_MS;
try {
const response = await requestGetPromise(url, payload, timeout);
return response.response;
if (response.response.missing_div_ids.length) {
console.warn(`Failed to fetch multiple div_ids: ${response.response.missing_div_ids}`);
}
return response.response.data;
} catch (error) {
console.error(JSON.stringify(error));
return {};
@ -447,7 +450,10 @@ class ExtraNetworksTab {
const timeout = EXTRA_NETWORKS_REQUEST_GET_TIMEOUT_MS;
try {
const response = await requestGetPromise(url, payload, timeout);
return response.response;
if (response.response.missing_div_ids.length) {
console.warn(`Failed to fetch multiple div_ids: ${response.response.missing_div_ids}`);
}
return response.response.data;
} catch (error) {
console.error(JSON.stringify(error));
return {};

View file

@ -901,11 +901,14 @@ def fetch_tree_data(
page = get_page_by_name(extra_networks_tabname)
res = {}
missed = []
for div_id in div_ids.split(","):
if div_id in page.tree:
res[div_id] = page.tree[div_id].html
else:
missed.append(div_id)
return JSONResponse(res)
return JSONResponse({"data": res, "missing_div_ids": missed})
def fetch_cards_data(
@ -924,11 +927,14 @@ def fetch_cards_data(
page = get_page_by_name(extra_networks_tabname)
res = {}
missed = []
for div_id in div_ids.split(","):
if div_id in page.cards:
res[div_id] = page.cards[div_id].html
else:
missed.append(div_id)
return JSONResponse(res)
return JSONResponse({"data": res, "missing_div_ids": missed})
def init_cards_data(tabname: str = "", extra_networks_tabname: str = "") -> JSONResponse: