I have my service signUp
async signUp(credentials: ICreateCredentials) {
try {
const user = await Auth.signUp({
username : credentials.email,
password: credentials.password,
attributes: {
email: credentials.email,
phone_number: ''
}
});
return user;
} catch (error) {
console.log(" sign up error ");
throw error;
}
}
This service is called in my register.component.ts file
async onSubmit() {
if (!this.registerForm.valid || this.buttonDisabled) {
return;
}
this.buttonDisabled = true;
this.buttonState = 'show-spinner';
try {
const user = this.authService.signUp(this.registerForm.value);
console.log({ user });
} catch (error) {
console.log(' ooook');
// The registration failed
this.notifications.create(
'Error',
error.message,
NotificationType.Bare,
{ theClass: 'outline primary', timeOut: 6000, showProgressBar: false }
);
this.buttonDisabled = false;
this.buttonState = '';
}
}
When Auth.signUp function raise an error, i can see "sign up error" then the stack trace in my browser, I never enter inside the catch of submit to handle it correctly in a pop up.
I get the message error in my browser:
ERROR Error: "Uncaught (in promise): Object: {"code":"UsernameExistsException","name":"UsernameExistsException", "message":"An account with the given email already exists."}"
What is wrong with my code ? Thanks in advance.