简体   繁体   中英

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. I'm first creating an observable from a promise and then I'm trying to use catcherror to get the error. I have a rule set up in the storage rules to not allow files larger than 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? 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. I wasn't dispatching the action in the 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})))))
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM