Good afternoon!
I’ve been having a little trouble implementing custom error handling for my signup function.
Ideally I would like to handle any errors from sign-up, log-in and wallet authentication by saving them to state within the Next.js project and use them in custom alerts to the user.
I noticed in the react-moralis docs, it mentions “most hooks” having an error variable provided by default which I can see displayed in the console but any additional use of this variable in my catch block is being ignored. In the case bellow this refers to the alert but any other logic using the error is also ignored.
Here is my function:
const handleSignup = async () => {
try {
await signup(form.username, form.password);
} catch (error) {
alert(error);
}
};
Ironically, when adding the {throwOnError = true} to the arguments for signup() I get the intended behavior, the custom error alert works, but the error that is returned is complaining that the email format should be of type string. Adding a dummy email parameter also doesn’t change this behavior.
Is there a way that a user can sign-up with just username and password and I am still able to use the throwOnError argument?