I have a smart contract with this simple function:
function addUser( string memory _username, string memory _nome, string memory _cognome, string memory _email) public isOwner() {
require(bytes(_username).length > 0 , "Username vuoto");
require(bytes(_nome).length > 0 , "Nome vuoto");
require(bytes(_cognome).length > 0 , "Cognome vuoto");
require(bytes(_email).length > 0 , "Email vuota");
if(checkUsernameExisting(_username)==0)
{
userCount ++;
users[userCount] = User(userCount, _username, _nome, _cognome, _email);
emit UserAdded(userCount, _username, _nome, _cognome, _email);
}
else
{
**revert("User already exists");**
}
}
I interact correctly with its in javascript using truffle
...
App.partecipazioneContest = await App.contracts.PartecipazioneContest.deployed()
...
try {
...
await App.partecipazioneContest.addUser(username, nome, cognome, email);
} catch (error) {
window.alert(error);
}
Is there any way to get the reason message? (in this case "User already exists").
In my catch block I get an error but I can not find the way to get the revert error message. (emit event doesn't work).
(Update) The error that I catch:
errorStatusError: Transaction:
0x247eeddd17eccae3376aea92587fd395d46202d78bb3aa0a9d4a0b05607de7e3 exited
with an error (status 0).
Please check that the transaction:
- satisfies all conditions set by Solidity `require` statements.
- does not trigger a Solidity `revert` statement.