daddy/frontend/src/store/sagas/failure.ts

21 lines
514 B
TypeScript
Raw Normal View History

2020-06-15 18:10:06 +02:00
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),
]);
}
2020-06-15 18:10:06 +02:00
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);
};
}