I've got a getContract function that looks something like this.
const getContract = async () => {
const provider = new ethers.providers.InfuraProvider(process.env.NETWORKS, process.env.ENDPOINT_KEY);
let wallet = ethers.Wallet.fromMnemonic(process.env.MNEMONIC);
const isReady = await provider.ready;
if(isReady){
wallet = wallet.connect(provider);
const contractAddress = WakandaVotingPlatform.networks["4"].address;
return new ethers.Contract(contractAddress, WakandaVotingPlatform.abi, wallet);
}
console.log(isReady);
}
My goal is to check if provider is ready to do it's job, and if for some reason it's not (the internet is down) I want to return something else instead of the contract, but this just doesn't seem to work. What would be the proper way to handle such error.