简体   繁体   English

如何从 Angularfire 承诺创建的可观察对象中捕获错误

[英]How do I catch an error from an observable created from an Angularfire promise

I'm trying to upload a file in an angular app to firebase using angularfire.我正在尝试使用 angularfire 将 angular 应用程序中的文件上传到 firebase。 I'm first creating an observable from a promise and then I'm trying to use catcherror to get the error.我首先从承诺创建一个可观察的对象,然后我尝试使用 catcherror 来获取错误。 I have a rule set up in the storage rules to not allow files larger than 1MB.我在存储规则中设置了一个规则,不允许大于 1MB 的文件。 When I try to upload a file larger, it doesn't allow it but I'm also not getting an error either.当我尝试上传更大的文件时,它不允许这样做,但我也没有收到错误消息。 Does it have to do with the creation of the observable using from?它与使用 from 创建可观察对象有关吗? Here is my code.这是我的代码。

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})))
    )

Sorry it was a mistake with the ngrx.抱歉,这是 ngrx 的错误。 I wasn't dispatching the action in the catchError.我没有在 catchError 中调度动作。 Should be应该

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.

相关问题 RxJS catchError运算符未在Promise创建的可观察对象上捕获错误 - RxJS catchError operator does not catch an error on an observable created from a Promise 如何从 Firestore 中的 Observable 中捕获错误? - How do I catch an error from Observable in Firestore? 处理from()创建的Observable中诺言抛出的错误 - Handling errors thown by promise in observable created by from() 可观察的Promise错误未调用catch - Promise Error in Observable not calling catch 离子2:如何从创建的Observable中获取错误? - Ionic 2: how to get error from created Observable? 如何从Promise返回Observable - How to return Observable from Promise 如何在AngularFire Observable中引发错误 - How to Throw error in AngularFire Observable 我是否需要取消订阅已使用 Observable.from() 转换为 Observable 的 Promise? - Do i need to unsubscribe from a Promise that has been converted to an Observable with Observable.from()? 如何获取可观察的 <Array[]> 从angularfire2中的引用数组? - How to retrieve Observable<Array[]> from array of references in angularfire2? 如何从 angularfire 获取变量,即使它是可观察的? - How to get a variable from angularfire, even though it is an observable?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM