How do I surface error messages from assert statements so a frontend can use them in AssemblyScript?

Viewed 53

Looking for a way to catch errors (in AssemblyScript) that occur to display proper error information/next steps to users on the frontend. Two scenarios - similar issues:

  1. When an assert statement triggers and stops the contract (panic) - I can have it display a useful error in the console, but not sure how to get that error to the frontend to do something meaningful with it.

  2. Currently, if a transaction is submitted requiring a wallet approval, user is directed to the wallet. After approving, if an assert statement fails in the transaction function, the wallet indicates there is an error/may want to try again. The assert statement has an useful error message, but one has to visit the NEAR explorer for the transaction to see it.

In both cases, the user isn't alerted to what's wrong/what needs to be fixed and is simply left with an non functioning app. Is there a way to catch the errors or surface them to the frontend to do something meaningful with them?

1 Answers
Related