rpc-errors
rpc-errors copied to clipboard
Metamask error instanceof EthereumRpcError, EthereumProviderError
Hi! I tried instanceof for the metamask error. Unfortunately, the verification was not passed, as it should be? Or am I doing something wrong?
how are you catching this error?
how are you catching this error?
So, I call signMessage
method in MetaMask provider, then I clicked the cancel button in the MetaMask extension.
try {
const signer = provider.getSigner();
const signature = await signer.signMessage('some message');
} catch (err) {
if (err instanceof EthereumProviderError || err instanceof EthereumRpcError) {
console.log('error');
} else {
console.log('not error');
}
}
@FanManutd How I prevent the inpage.js error to appear in my console? I mean I catch the error and I handle it in my javascript, but metamask still threw and display the RPC error, exactly as it showed in your image.
I don't understand why the error still appears in console despite I am catching it in a try/catch . Do you have idea of how avoid that the message is duplicated?
how are you catching this error?
So, I call
signMessage
method in MetaMask provider, then I clicked the cancel button in the MetaMask extension.try { const signer = provider.getSigner(); const signature = await signer.signMessage('some message'); } catch (err) { if (err instanceof EthereumProviderError || err instanceof EthereumRpcError) { console.log('error'); } else { console.log('not error'); } }
@FanManutd Did you find any solution to this?
Given your use of a provider and a signer, it appears that you may be using Ethers, which does not use this library to produce errors. However, we would need more information about your project in order to replicate this error. If it's possible to replicate on CodeSandbox or a similar service, that would help us triage your issue much more easily. I'm going to close this issue, but feel free to give us more information and I can reopen this.