I want to log the error message in the console. Everything is working fine except that I could not log only the message for eg if the email already exists it should log "email exists"
const submitHandler = async(event) => {
event.preventDefault();
const enteredEmail = emailInputRef.current.value;
const enteredPassword = passwordInputRef.current.value;
try {
if (isLogin) {
//do something
}
else {
setstate("sending request")
const response = await fetch(
"https://identitytoolkit.googleapis.com/v1/accounts:signUp?key=xxx",
{
method: "POST",
body: JSON.stringify({
email: enteredEmail,
password: enteredPassword,
returnSecureToken: true,
}),
headers: {
"Content-Type": "application/json",
},
}
)
if(response.ok){
alert("User added successfully")
}
else{
const data = await response.json()
console.log(data);
throw new Error(data);
}
setstate("Create new account")
}
} catch (error) {
console.log(error.message);
}
};