rpc-errors icon indicating copy to clipboard operation
rpc-errors copied to clipboard

Metamask error instanceof EthereumRpcError, EthereumProviderError

Open FanManutd opened this issue 2 years ago • 2 comments

Hi! I tried instanceof for the metamask error. Unfortunately, the verification was not passed, as it should be? Or am I doing something wrong? image image

FanManutd avatar Jun 02 '22 13:06 FanManutd

how are you catching this error?

wobsoriano avatar Jun 09 '22 21:06 wobsoriano

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 avatar Jun 10 '22 05:06 FanManutd

@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?

Dinuz avatar Oct 29 '22 00:10 Dinuz

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?

mmiranda-stackit avatar Nov 02 '22 00:11 mmiranda-stackit

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.

mcmire avatar Nov 09 '23 18:11 mcmire