Is there any function inside MetaMask or Web3JS to detect if the node is down? For example, let say the private node that the user is connected to is down, how my app can know about it?
Steps to reproduce in local environment:
- Launch your Dapp in local mode
- Connect to a private node i.e. Ganache
- Unlock MetaMask
- Quit or kill the private node i.e. Ganache
- Go back to Dapp, check MetaMask
In above scenario, MetaMask doesn't produce/show any error to user mentioning the node is down. MetaMask still keeping a state of that node and assumes the node is still alive.
I try to handle this manually by creating a 'ping'-like function. But, due to the nature of CORS, that's not possible because in order to comply with CORS, it assume both Dapp and private node are on same protocol, host and port number. So, my 'ping'-like function didn't work.
So, my question here is, does MetaMask or Web3JS provide any function to call to detect if the RPC node is down/not reachable?