diff --git a/packages/server-admin-ui/src/actions.js b/packages/server-admin-ui/src/actions.js index 190290de3..bab027b87 100644 --- a/packages/server-admin-ui/src/actions.js +++ b/packages/server-admin-ui/src/actions.js @@ -110,18 +110,20 @@ export function restart() { } } -// Build actions that perform a basic authFetch to the backend. Pull #514. -export const buildFetchAction = (endpoint, type, prefix) => (dispatch) => - authFetch( - `${isUndefined(prefix) ? window.serverRoutesPrefix : prefix}${endpoint}` - ) - .then((response) => response.json()) - .then((data) => +export const buildFetchAction = + (endpoint, type, prefix) => async (dispatch) => { + const response = await authFetch( + `${isUndefined(prefix) ? window.serverRoutesPrefix : prefix}${endpoint}` + ) + + if (response.status === 200) { + const data = await response.json() dispatch({ type, data, }) - ) + } + } export const fetchLoginStatus = buildFetchAction( '/loginStatus',