Skip to content

Commit

Permalink
check incoming data some more, fwiw
Browse files Browse the repository at this point in the history
  • Loading branch information
Hans Acker committed Oct 16, 2024
1 parent 71b1bc1 commit 43da4e0
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions html/js/board.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,23 @@ ws.onmessage = (event) => {

try {
data = JSON.parse(event.data);

// TODO: check typeof === "object"?
if (!(data.$schemaRef && data.header && data.message)) {
console.log("Invalid message:", data);
activity.error();
return;
}
} catch(error) {
console.log("JSON parse error:", error);
console.log("JSON object error:", error);
activity.error();
return;
}

const schemaRef = data.$schemaRef;
const header = data.header;
const message = data.message;

if (!message) {
console.log("No message:", data);
activity.error();
return;
}

activity.ok();
lastEvent = Date.now();

Expand All @@ -133,7 +136,7 @@ ws.onmessage = (event) => {
const oldCount = tbody.childElementCount;

// TODO: group totals by softwareName, collapse individual versions
softwareStats.inc(`${data.header.softwareName} ${data.header.softwareVersion}`);
softwareStats.inc(`${header.softwareName} ${header.softwareVersion}`);

if (tbody.childElementCount != oldCount) {
tbody.replaceChildren(...[...tbody.children].sort((a, b) => a.children[0].textContent < b.children[0].textContent ? 1 : -1));
Expand Down

0 comments on commit 43da4e0

Please sign in to comment.