1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-19 13:19:44 +02:00
planka/client/src/sagas/app/requests/request.js
2019-10-05 06:12:36 +05:00

24 lines
597 B
JavaScript
Executable file

import {
call, put, select, take,
} from 'redux-saga/effects';
import { accessTokenSelector } from '../../../selectors';
import { logout } from '../../../actions';
import ErrorCodes from '../../../constants/ErrorCodes';
export default function* (method, ...args) {
try {
const accessToken = yield select(accessTokenSelector);
return yield call(method, ...args, {
Authorization: `Bearer ${accessToken}`,
});
} catch (error) {
if (error.code === ErrorCodes.UNAUTHORIZED) {
yield put(logout()); // TODO: next url
yield take();
}
throw error;
}
}