Skip to content

Commit 404b669

Browse files
Check if server is accessible first, fix function name [ci skip]
1 parent 24143ee commit 404b669

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

buildingspy/templates/plot.html

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<html>
22
<head>
33
<meta charset="utf-8" />
4+
<link rel="icon" href="data:;base64,iVBORw0KGgo=" />
45
<title>$PAGE_TITLE</title>
56
<script src="https://cdn.plot.ly/plotly-3.0.1.min.js" charset="utf-8"></script>
67
</head>
@@ -59,19 +60,25 @@
5960
const fileInfo = []; // To track which variable each promise belongs to
6061

6162
// Collect all groups and prepare file loading
62-
Object.keys(dict_var_info).forEach((v) => {
63-
dict_var_info[v].forEach((el) => {
64-
avail_groups.push(el["group"]);
65-
});
66-
67-
// Prepare file loading for each variable
68-
const fileTypes = ["reference.csv", "test.csv", "errors.csv"];
69-
fileTypes.forEach((f) => {
70-
const file = [srv_url, dict_var_info[v][0]["dir"], f].join("/");
71-
filePromises.push(loadCSV(file));
72-
fileInfo.push({ variable: v, type: f });
63+
// Check if server is accessible first
64+
fetch(srv_url)
65+
.then(response => {
66+
if (!response.ok) {
67+
throw new Error(`Server not accessible (status: ${response.status})`);
68+
}
69+
Object.keys(dict_var_info).forEach((v) => {
70+
dict_var_info[v].forEach((el) => {
71+
avail_groups.push(el["group"]);
72+
});
73+
// Prepare file loading for each variable
74+
const fileTypes = ["reference.csv", "test.csv", "errors.csv"];
75+
fileTypes.forEach((f) => {
76+
const file = [srv_url, dict_var_info[v][0]["dir"], f].join("/");
77+
filePromises.push(loadCSV(file));
78+
fileInfo.push({ variable: v, type: f });
79+
});
80+
});
7381
});
74-
});
7582

7683
// Wait for all files to load
7784
const csvDataSets = await Promise.all(filePromises);
@@ -116,7 +123,7 @@
116123
console.error("Error loading or processing data:", error);
117124
document.getElementById("myDiv").innerHTML = `<div style="text-align:center;padding:20px;color:red;">
118125
Error loading data: ${error.message}<br>
119-
<button onclick="make_plot()">Retry</button>
126+
<button onclick="makePlot()">Retry</button>
120127
</div>`;
121128
}
122129
}

0 commit comments

Comments
 (0)