mirror of
https://github.com/Unleash/unleash.git
synced 2024-10-18 20:09:08 +02:00
22795e251f
* Setup create-react-app and typescript Co-authored-by: Fredrik Oseberg <fredrik.no@gmail.com>
21 lines
675 B
JavaScript
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 });
|