[英]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.