Search code examples
angularrxjsngrxangular7ngrx-store

With latest version of ngrx error handling not working


I am using latest version of ngrx, how to catch API error in effects. I tried all the tutorials and various examples but seems none of them is working for me.

This is the link for demo of what I am doing so far: https://stackblitz.com/edit/angular-cru1he

Expectation: I wants to catch API error and fire an action if api call fails.


Solution

  • In your effect, you have to return an observable of your GetStudiesFail so, you can try to replace your commented code by this :

    catchError(err => of(new StudyActions.GetStudiesFail(err)))
    

    simplified version of this

    catchError((err) => {return of(new StudyActions.GetStudiesFail(err))})
    

    currently in your stackblitz you didn't returned your action neither wrapped it in an observable