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

21 lines
531 B
TypeScript
Raw Normal View History

2020-06-15 18:10:06 +02:00
import { UnauthorizedError } from "../../util/daddy";
import { all, takeEvery } from 'redux-saga/effects';
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) {
// TODO Implements better authorization error handling
window.location.reload();
2020-06-15 18:10:06 +02:00
}
}
export function patternFromRegExp(re: any) {
return (action: any) => {
return re.test(action.type);
};
}