Gist
I have an Effect, that loads the reviews of a product through multiple API requests:
@Effect()
loadOfProduct$ = this.actions$.pipe(
ofType<ReviewsActions.LoadOfProduct>(ReviewsActions.Types.LOAD_OF_PRODUCT),
map(action => action.payload),
switchMap((productId: string) => {
return this.reviewsService.loadOfProduct(productId);
}),
switchMap((reviews: Review[]) => {
return forkJoin([
of(reviews),
this.productsService.loadManyById(reviews.map(r => r.productId)),
this.usersService.loadManyById(reviews.map(r => r.writerId)),
]);
}),
switchMap((data: any) => {
const [reviews, products, users] = data;
return [
new ProductsActions.LoadManyByIdSuccess(products),
new UsersActions.LoadManyByIdSuccess(users),
new ReviewsActions.LoadOfProductSuccess(reviews),
];
}),
catchError(error => of(new ReviewsActions.LoadOfProductFail({
...error.error,
// I need the productId here!!!
// payload: productId,
}))),
);
Issue
The issue is, that I don't know how to access the productId
string from the first switchMap
in the catchError