1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-18 20:09:08 +02:00
unleash.unleash/frontend/src/store/util.js
Christopher Kolstad 22795e251f Migrate to create-react-app and react-scripts (#263)
* Setup create-react-app and typescript

Co-authored-by: Fredrik Oseberg <fredrik.no@gmail.com>
2021-04-07 09:04:48 +02:00

21 lines
675 B
JavaScript

export const AUTH_REQUIRED = 'AUTH_REQUIRED';
export const FORBIDDEN = 'FORBIDDEN';
export function dispatchError(dispatch, type) {
return error => {
switch (error.statusCode) {
case 401:
dispatch({ type: AUTH_REQUIRED, error, receivedAt: Date.now() });
break;
case 403:
dispatch({ type: FORBIDDEN, error, receivedAt: Date.now() });
break;
default:
dispatch({ type, error, receivedAt: Date.now() });
break;
}
};
}
export const success = (dispatch, type, val) => value => dispatch({ type, value: val ? val : value });