File tree Expand file tree Collapse file tree 1 file changed +10
-5
lines changed
Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Original file line number Diff line number Diff line change 11import { EthereumRpcError } from 'eth-rpc-errors'
22
33export function handleError ( e : EthereumRpcError < unknown > ) : void {
4- const msg = e . message
4+ // tries to parse Internal JSON RPC error, see https://eips.ethereum.org/EIPS/eip-1474#error-codes
5+ if ( e . code === - 32603 ) {
6+ e = e . data as EthereumRpcError < unknown >
7+ }
8+
9+ const msg = e . message || 'Something went wrong.'
510 // checks if the user has metamask installed
611 if ( msg . includes ( 'missing provider' ) || msg . includes ( 'No provider found' ) ) {
712 throw new Error (
813 'Please install the MetaMask extension. If you are on mobile, open your MetaMask app and browse to this page.'
914 )
1015 }
1116
12- // ideally we would check for the error code here, but the same error code ( -32000)
13- // is used for more than one error type.
17+ // ideally we would check for the error code here, but the same error code: -32000 (Bad Input )
18+ // is used for more than one error type
1419 if ( msg . includes ( 'err: insufficient funds for gas * price + value' ) ) {
15- throw new Error ( 'You do not have enough balance.' )
20+ throw new Error ( 'Your wallet does not have enough balance.' )
1621 }
1722
18- throw Error ( e . message )
23+ throw Error ( msg )
1924}
You can’t perform that action at this time.
0 commit comments