0

I have the follow error object that was caught in a catch statement

Error: execution reverted: Auction owner is not authorized
{
  "originalError": {
    "code": 3,
    "data": "0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001f41756374696f6e206f776e6572206973206e6f7420617574686f72697a656400",
    "message": "execution reverted: Auction owner is not authorized"
  }
}

This error message was generated from this call to a smart contract instance, performed as the following

endAuction = async () => {

        try{ 

        const accounts = await web3.eth.getAccounts();
            //Create new instance of plastic bale SC that has been deployed 
            const plasticBaleSC = plasticBaleContract(this.props.address);
            await plasticBaleSC.methods.endAuction().call();  

            this.setState({notOver: false});
        } catch (err){
            console.log(err.originalError);
        }


    };

How can I extract message from that error object? I tried err.originalError.message and err.message but both methods failed.

0

I ran into the same issue and I noticed that this

Error: execution reverted: Auction owner is not authorized
{
  "originalError": {
    "code": 3,
    "data": "0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001f41756374696f6e206f776e6572206973206e6f7420617574686f72697a656400",
    "message": "execution reverted: Auction owner is not authorized"
  }
}

is the error message.

So in order to extract the additional info, you may use

const jsonStr = e.message.substr(e.message.indexOf('{'));
const json = JSON.parse(jsonStr);

Gives you the actual object. You can then access it with json.originalError.code or whatever.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.