mirror of
https://github.com/pezkuwichain/pezkuwi-telemetry.git
synced 2026-05-30 22:51:09 +00:00
fix: Crash when accessing network state for nodes that don't have it. (#144)
* fix: Crash when accessing network state for nodes that don't have it.
This commit is contained in:
@@ -62,9 +62,12 @@ http.createServer((request, response) => {
|
|||||||
const nodeList = Array.from(chain.nodeList());
|
const nodeList = Array.from(chain.nodeList());
|
||||||
const nodeId = Number(strNodeId);
|
const nodeId = Number(strNodeId);
|
||||||
const node = nodeList.filter((node) => node.id == nodeId)[0];
|
const node = nodeList.filter((node) => node.id == nodeId)[0];
|
||||||
if (node) {
|
if (node && typeof node.networkState === 'string') {
|
||||||
response.writeHead(200, {"Content-Type": "application/json"});
|
response.writeHead(200, {"Content-Type": "application/json"});
|
||||||
response.write(node.networkState);
|
response.write(node.networkState);
|
||||||
|
} else {
|
||||||
|
response.writeHead(404, {"Content-Type": "text/plain"});
|
||||||
|
response.write("Node has disconnected or has not submitted its network state yet");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user