【发布时间】:2015-01-29 17:30:55
【问题描述】:
这个try catch 块似乎没有捕捉到发生的错误,这很奇怪,考虑到我有一个类似的try catch 块用于站点的注册部分。这处理登录。错误发生在第三行email: $scope.authInfo.email,并抛出此错误:
Error: Firebase.authWithPassword failed: First argument must contain the key "email" with type "string"
当电子邮件格式错误时会出现这种情况,例如test@。因此,当我希望在 catch 块中设置错误消息时。
有人知道为什么这个try catch 不起作用吗?
try {
$scope.syncAuth.$authWithPassword({
email: $scope.authInfo.email,
password: $scope.authInfo.password
}).then(function(authData) {
$scope.isSuccessful = true;
$scope.success = 'You have successfully logged in - Redirecting...';
$rootScope.loggedIn = true;
$timeout($scope.redirectUser, 3000);
}).catch(function(error) {
switch (error.code) {
case 'INVALID_USER': $scope.errors.push('The email you have entered is not a registered user.');
break;
case 'INVALID_PASSWORD': $scope.errors.push('Invalid password.');
break;
}
});
}
catch (err) {
$scope.errors.push('Invalid email format.')
}
【问题讨论】:
标签: javascript angularjs try-catch angularfire