May be there is a different way to solve it (like create another selector especially for errors)
export const getMSFState = createFeatureSelector<STState>('st');
export const selectCreatedSensor = createSelector(
getMSFState,
selectAllSensors,
(state: STState, sensorArray: SeasonTotals[], props: { blockId: number}) => {
const isSuccessCreate = state.action === fromST.ST_ADD_ELEMENT && !state.loading && !state.error;
const isAnErrorCreate = state.action === fromST.ST_ADD_ELEMENT && !state.loading && state.error;
if (isAnErrorCreate) {
return throwError('Error X');
}
const blockSensors = [...sensorArray].filter(s => s.blockId = props.blockId);
return isSuccessCreate ? blockSensors.pop() : null;
}
);
I want to catch the second subscribe parameter (the error one), but I don't know if is possible to emit it in the NgRx selector
this.store.pipe(
select(STSelectors.selectCreatedSensor, { blockId: this.id })
).subscribe((data) => {
console.log('success creation', data);
}, (error) => {
// I can't catch this, instead I catch it in the first subscribe parameter (in the success one)
// And the value emited is an Observable object
console.log('something went wrong', error);
})