2
votes

I have an angular app using an ngrx effect that I am loading firestore data with. I currently get this warning:

You provided '() => ({ type })' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable.

Here is my ngrx effect

loadVendors$: Observable<Action> = createEffect(() => this.actions$.pipe(
		ofType(fromVendorActions.loadVendors),
		switchMap(() => this.store.select(fromRoot.getRouterState)),
		tap((ev: any)=> console.log('before', ev)),
		switchMap((action:any) => this.vendorService.getVendors(action.state.params.vendorGroupId)),
		tap((ev: any)=> console.log('after', ev)),
		map((vendors: any) => fromVendorActions.loadVendorsSuccess({vendors: vendors})),
		catchError(() => fromVendorActions.loadVendorsFail)
	))

I am switching from the action, getting the parameter of the page I'm on, then switching to the observable from my service to retrieve some data as an observable.

Using tap() to check the stream I seem to get what I'd expect. The warning appears in the console between the (2) taps where I'm logging the streams. The data IS loading into the store correctly but the warning is bugging me.

2

2 Answers

5
votes

The catchError should return an observable:

catchError(() => of(fromVendorActions.loadVendorsFail))
1
votes

you have always to catch errors in effect and return a new Observable to keep the stream from dying and without it we’ll never find out that an action has failed