You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There have been several community developers who've asked about the possibility of secretjs returning nicely typed error messages so that we don't need to do messy string matching. For example, Secret DreamScape's global error parsing looks like this:
exportfunctionhandleSecretJsError(e){console.log(e);if(e.message.match(/insufficient fee/g)){const[,amountGot,amountRequired]=/got: (\d+)uscrt required: (\d+)uscrt/g.exec(e.message);returnalert(`Not enough gas fees. You need ${amountRequired}uscrt, but you sent ${amountGot}uscrt.`);}if(e.message.match(/Invalid recipient address/g)){returnalert(`Invalid recipient address.`);}if(e.message.match(/out of gas/g)){const[,gasWanted,gasUsed]=/gasWanted: (\d+), gasUsed: (\d+)/g.exec(e.message);returnalert(`Not enough gas. You need ${gasWanted} gas, but you used ${gasUsed} gas.`);}if(e.message.match(/timed out waiting for tx to be included in a block/g))returnalert("Transaction timed out. Please try again.");if(e.message.match(/Error: Account does not exist on chain. Send some tokens there before trying to query nonces./g))returnalert("Please send some SCRT to your in-game wallet address and try again.");if(e.message.match(/insufficient funds/g)){const[,amountAvailable,amountRequired]=/(\d+)uscrt is smaller than (\d+)uscrt/g.exec(e.message);returnalert(`You don't have enough funds to complete this transaction. ${formatMoney(parseInt(amountAvailable))} SCRT available, ${formatMoney(parseInt(amountRequired))} SCRT required.`);}letmessage=e.message.substr(e.message.indexOf("encrypted:")+11);message=message.substr(0,message.indexOf(": execute contract failed"));constmessageText=JSON.parse(message).generic_err.msg;alert(messageText);}
The text was updated successfully, but these errors were encountered:
There have been several community developers who've asked about the possibility of secretjs returning nicely typed error messages so that we don't need to do messy string matching. For example, Secret DreamScape's global error parsing looks like this:
The text was updated successfully, but these errors were encountered: