我有我的服务注册
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;
}
}
此服务在我的register.component.ts文件中调用
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 = '';
}
}
当Auth.signUp函数引发错误时,我可以在浏览器中看到“注册错误”,然后显示堆栈跟踪,我从不进入内部提交以在弹出窗口中正确处理它。
我在浏览器中收到消息错误:
ERROR错误:“未捕获(承诺):对象: {“代码”:“ UsernameExistsException”,“名称”:“ UsernameExistsException”, “ message”:“具有给定电子邮件的帐户已经存在。”}“
我的代码有什么问题? 预先感谢。