Это пример из редукс-наблюдаемого
import { ajax } from 'rxjs/ajax';
const fetchUserEpic = action$ => action$.pipe(
ofType(FETCH_USER),
mergeMap(action => ajax.getJSON(`/api/users/${action.payload}`).pipe(
map(response => fetchUserFulfilled(response)),
catchError(error => of({
type: FETCH_USER_REJECTED,
payload: error.xhr.response,
error: true
}))
))
);
И здесь принято решение
import { FETCHING_DATA } from '../constants'
import { getDataSuccess, getDataFailure } from './actions'
import getPeople from '../api'
import { from, of } from 'rxjs';
import { map, catchError, mergeMap } from 'rxjs/operators';
import { ofType } from 'redux-observable';
const fetchUserEpic = action$ => action$.pipe(
ofType(FETCHING_DATA),
mergeMap(() => from(getPeople()).pipe(
map(getDataSuccess),
catchError(error => of(getDataFailure(error)))
))
);
export default fetchUserEpic;