0
votes

I am using ngrx stores and calling an API inside effects and I want to get the error in the subcription of one action if api fails

example

this.store.pipe(select(economicEntriesReducer.getEconomicEntries)).subscribe(
    (response) => { // getting response here if api in effect is successful}
    (error) => { // how do i make it work });

I am returning the state from reducers

export const getEconomicSupplierGroups = createSelector( getEconomicEntriesState, state => { return state; } );

and handing the call like this in effects

return this.httpService.get('economic/entries').pipe(map(
    (response: Supplier[]) => {
        return new economicEntriesActions.GetEntriesSuccess(<Supplier[]>response);
    }),
    catchError(error => of(new economicEntriesActions.GetEntriesError(error)))
);
1

1 Answers

0
votes

Reducers and selectors shouldn't throw errors.

Instead you should create a getErrors selector if you want to do something with the error. More info at Handling Error States with NgRx