[英]RxJS catchError operator does not catch an error on an observable created from a Promise
[英]How do I catch an error from an observable created from an Angularfire promise
我正在嘗試使用 angularfire 將 angular 應用程序中的文件上傳到 firebase。 我首先從承諾創建一個可觀察的對象,然后我嘗試使用 catcherror 來獲取錯誤。 我在存儲規則中設置了一個規則,不允許大於 1MB 的文件。 當我嘗試上傳更大的文件時,它不允許這樣做,但我也沒有收到錯誤消息。 它與使用 from 創建可觀察對象有關嗎? 這是我的代碼。
let ref = this.afStorage.ref(`/folder`);
return from(ref.put(file)).pipe(
tap(() => this.store.dispatch(fromRoot.loadSuccess({message: `File Uploaded Successfully`, showMsg: true}))),
catchError(err => of(fromRoot.loadFail({message: `Failed To Upload File`, showMsg: true, error: err})))
)
抱歉,這是 ngrx 的錯誤。 我沒有在 catchError 中調度動作。 應該
let ref = this.afStorage.ref(`/folder`);
return from(ref.put(file)).pipe(
tap(() => this.store.dispatch(fromRoot.loadSuccess({message: `File Uploaded Successfully`, showMsg: true}))),
catchError(err => of(this.dispatch(fromRoot.loadFail({message: `Failed To Upload File`, showMsg: true, error: err})))))
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.