我在我的網站上做了一個auth,它工作正常,但我想處理錯誤,爲了測試我爲此目的使用firebase返回這個目的:「已經有一個帳戶存在相同的電子郵件地址但登錄憑據不同,請使用與此電子郵件地址相關的提供商登錄。「我試着寫一個RXjs觀察到這樣做,用下面的代碼:Angularfire2和Rxjs Observable沒有發射Catch和完整的方法
private subscribleAuth() {
this.af.auth
.subscribe(
auth => {
this._auth = auth && auth.auth ? auth.auth : null;
if (this._auth) {
this.loginState = 'logged';
} else {
this.loginState = 'login';
}
},
err => {
console.log('error'),
this.loginState = 'error';
},
() => { console.log('done.') }
);
}
我的控制檯從來沒有顯示「錯誤」或「做」,所以任何我把ERR代碼中不起作用。
注:我知道是什麼原因導致火力點回報,我只是想知道如何對待它,爲什麼我寫的代碼沒有預期一樣,當沒有返回錯誤,該網站按預期工作具有相同的可觀察性。
我使用angularfire2:^ 2.0.0-beta.5與角2.0.0最終
編輯2:reported as an issue,也許這真是一個錯誤,要保持這個發佈更新。現在正在使用此代碼在GitHub上寫的yashmurty的workarround:
import { AngularFire, AuthProviders } from 'angularfire2';
import { AuthBackend } from 'angularfire2/auth/auth_backend';
export class SocialmenuComponent {
constructor(public af: AngularFire, private _authBackend: AuthBackend) {
// this.af.auth.subscribe(
this._authBackend.getRedirectResult().subscribe(
(auth) => {
if(auth) {
console.log(auth);
} else {
console.log('User Not Logged In');
}
},
(err) => {
if(err) {
console.log('Error in auth.subscribe : ');
console.log(err);
} else {
console.log('No Error detected in auth.subscribe');
}
},
() => { console.log('done.') }
);
}
}
你的意思是這行'this.af.auth.subscribe(auth => console.log(auth));'?但那不是你在做什麼。看看最底層:https://github.com/angular/angularfire2/blob/master/docs/5-user-authentication.md#cordova-case 它們綁定'.then()'和'.catch() '從auth()返回Promise。signInWithCredential(provider)'。這就是你可以捕捉錯誤的方法。 – martin
這就是apache cordova的情況,如果我使用彈出方法,也應該工作,我使用重定向方法,因此頁面重定向到提供程序頁面失去內存上的所有變量/狀態(然後funcion被調用重定向),再次當它回到我的頁面,如果我打電話auth.login將再次重定向到提供商頁面在無限循環... – Hllink
我可以捕獲這樣的錯誤,但我仍然得到error_handler中引發的異常。 js和訂閱者。JS - 他們似乎打破了程序的執行 - 任何方式來沉默/忽略這些錯誤? –