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:
Maciej Hirsz
2019-05-13 13:18:24 +02:00
committed by GitHub
parent 2ec4269699
commit 74c784c62d
+4 -1
View File
@@ -62,9 +62,12 @@ http.createServer((request, response) => {
const nodeList = Array.from(chain.nodeList());
const nodeId = Number(strNodeId);
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.write(node.networkState);
} else {
response.writeHead(404, {"Content-Type": "text/plain"});
response.write("Node has disconnected or has not submitted its network state yet");
}
}
}