I have a problem with using : web3.net.listening The case when I am connected to the testRPC is working and it returns me TRUE. But the case I am not connected it returns me INTERNAL SERVER ERROR. I understand that this "listening" object doesn't exist when I am no longuer connected to testRPC. How can I solve this? so I can get false as result if testrpc not connected.
const config = require('config');
const Router = require('koa-router');
const router = new Router();
const Web3 = require('web3');
const web3 = new Web3();
web3.setProvider(new web3.providers.HttpProvider(config.provider.url));
router.get('/cbn/provider-status', ctx => {
const listening = web3.net.listening;
if (listening){
ctx.body = {"status":listening}
}
else ctx.body = {"status":"false"}
})
Many Thanks in advance.