import { UnauthorizedError } from "../../util/daddy"; import { put, all, takeEvery } from 'redux-saga/effects'; import { logout } from '../actions/auth'; export function* failureRootSaga() { yield all([ takeEvery(patternFromRegExp(/^.*_FAILURE/), failuresSaga), ]); } export function* failuresSaga(action) { if (action.error instanceof UnauthorizedError) { yield put(logout()); } } export function patternFromRegExp(re: any) { return (action: any) => { return re.test(action.type); }; }