Better error handling for when the server is inaccessible/down.
This commit is contained in:
parent
c44506dbec
commit
f024e1a1cf
@ -5,9 +5,12 @@ async function refresh_overview(server_address) {
|
||||
const data = await response.json();
|
||||
if (!("error" in data)) {
|
||||
return { overview: data, error: null };
|
||||
} else {
|
||||
return { overview: null, error: data };
|
||||
}
|
||||
} else {
|
||||
return { overview: null, error: null };
|
||||
}
|
||||
return { overview: null, error: null };
|
||||
} catch (e) {
|
||||
return { overview: null, error: e };
|
||||
}
|
||||
|
@ -8,14 +8,16 @@ var current_checks = 0;
|
||||
var current_entrances = 0;
|
||||
var current_codes = Number.MAX_VALUE;
|
||||
var current_hints = 0;
|
||||
var total_checks = 0;
|
||||
var total_entrances = 0;
|
||||
|
||||
// Global state internal
|
||||
var server_address = "localhost:51111/";
|
||||
var cross_codes = {};
|
||||
var can_access_api_server = true;
|
||||
var is_timeout = false;
|
||||
var hide_completed_areas = false;
|
||||
var cross_codes = {};
|
||||
var total_checks = 0;
|
||||
var total_entrances = 0;
|
||||
var all_scenes = [];
|
||||
|
||||
window.onload = async () => {
|
||||
await get_updated_server_address();
|
||||
@ -28,7 +30,7 @@ window.onload = async () => {
|
||||
refresh_elements();
|
||||
},
|
||||
(error) => {
|
||||
console.log(error);
|
||||
console.error(error);
|
||||
}
|
||||
);
|
||||
};
|
||||
@ -38,7 +40,7 @@ async function get_updated_server_address() {
|
||||
.then(
|
||||
(response) => response.json(),
|
||||
(error) => {
|
||||
console.log("Are you sure the front end is up?");
|
||||
console.error(error);
|
||||
}
|
||||
)
|
||||
.then(
|
||||
@ -47,7 +49,7 @@ async function get_updated_server_address() {
|
||||
server_address = parsed_data["listen_address"];
|
||||
},
|
||||
(error) => {
|
||||
console.log(error);
|
||||
console.error(error);
|
||||
}
|
||||
);
|
||||
}
|
||||
@ -69,6 +71,7 @@ async function initialize_elements() {
|
||||
current_entrances = entrances.found;
|
||||
total_checks = checks.total;
|
||||
total_entrances = entrances.total;
|
||||
all_scenes = Array.from(Object.keys(checks.scenes));
|
||||
await update_overview(overview, false);
|
||||
|
||||
// Initialize breakdown list
|
||||
@ -111,23 +114,34 @@ async function refresh_elements() {
|
||||
|
||||
if (response.overview) {
|
||||
if (!can_access_api_server) {
|
||||
console.log("I found the server!");
|
||||
console.info("I found the server!");
|
||||
document.getElementById("status-block").classList.add("hidden");
|
||||
can_access_api_server = true;
|
||||
await initialize_elements();
|
||||
}
|
||||
is_timeout = false;
|
||||
await update_if_changes(response.overview);
|
||||
} else if (response.error.error) {
|
||||
if (!is_timeout) {
|
||||
is_timeout = true;
|
||||
console.debug("Received timeout from API server.");
|
||||
}
|
||||
if (!can_access_api_server) {
|
||||
console.info("I found the server!");
|
||||
document.getElementById("status-block").classList.add("hidden");
|
||||
can_access_api_server = true;
|
||||
}
|
||||
} else {
|
||||
if (can_access_api_server) {
|
||||
console.log("Could not access the API server.");
|
||||
console.debug("Could not access the API server.");
|
||||
document.getElementById("status-block").classList.remove("hidden");
|
||||
}
|
||||
can_access_api_server = false;
|
||||
}
|
||||
setTimeout(refresh_elements, 2000);
|
||||
setTimeout(refresh_elements, 500);
|
||||
}
|
||||
|
||||
async function update_if_changes(overview) {
|
||||
document.getElementById("status-block").classList.add("hidden");
|
||||
|
||||
const changed_seed = overview.seed != current_seed;
|
||||
const changed_scene = overview.scene != current_scene;
|
||||
const changed_checks = overview.items != current_checks;
|
||||
@ -160,7 +174,7 @@ async function perform_updates(
|
||||
) {
|
||||
if (changed_seed) {
|
||||
initialize_elements();
|
||||
console.log(`Seed changed to: ${current_seed}`);
|
||||
console.info(`Seed changed to: ${current_seed}`);
|
||||
} else {
|
||||
if (changed_checks) {
|
||||
update.refresh_checks(server_address).then((data) => {
|
||||
@ -203,7 +217,7 @@ async function update_overview(overview, changed_scene) {
|
||||
current_entrances = overview.entrances;
|
||||
current_hints = overview.hints;
|
||||
|
||||
if (changed_scene) {
|
||||
if (changed_scene && all_scenes.some((scene) => scene == overview.scene)) {
|
||||
await update_scene(overview.scene);
|
||||
}
|
||||
}
|
||||
@ -343,7 +357,7 @@ async function apply_summary_colors(summary) {
|
||||
"text-highlight-empty-text",
|
||||
"text-highlight-undiscovered-text"
|
||||
);
|
||||
if (summary.checks_total > 0 && summary.entrances_total > 0) {
|
||||
if (summary.checks_total > 0 || summary.entrances_total > 0) {
|
||||
if (
|
||||
summary.checks_collected == summary.checks_total &&
|
||||
summary.entrances_found == summary.entrances_total
|
||||
|
Loading…
Reference in New Issue
Block a user