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(/insufficientfee/g)){const[,amountGot,amountRequired]=/got:(\d+)uscrtrequired:(\d+)uscrt/g.exec(e.message);returnalert(`Not enough gas fees. You need ${amountRequired}uscrt, but you sent ${amountGot}uscrt.`);}if(e.message.match(/Invalidrecipientaddress/g)){returnalert(`Invalid recipient address.`);}if(e.message.match(/outofgas/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(/timedoutwaitingfortxtobeincludedinablock/g))returnalert("Transaction timed out. Please try again.");if(e.message.match(/Error:Accountdoesnotexistonchain.Sendsometokenstherebeforetryingtoquerynonces./g))returnalert("Please send some SCRT to your in-game wallet address and try again.");if(e.message.match(/insufficientfunds/g)){const[,amountAvailable,amountRequired]=/(\d+)uscrtissmallerthan(\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: