With this method app is listening for chain change:
ethereum.on('chainChanged', (chainId) => {
})
but if the chain to which the user is going is not added yet into metamask it throws :
inpage.js:1 MetaMask - RPC Error: Unrecognized chain ID "0x89".
Try adding the chain using wallet_addEthereumChain first. Object
of course, there is a method to add a new chain into metamask but how to catch this metamask error? try and catch outside ethereum.on gives nothing
Thanks!