diff --git a/src/features/system/actionCreators.js b/src/features/system/actionCreators.js index 5c4ce58..bb2e779 100644 --- a/src/features/system/actionCreators.js +++ b/src/features/system/actionCreators.js @@ -1,21 +1,19 @@ import * as types from "./actionTypes"; -import * as api from "./api"; +import api from "./api"; import { beginApiCall, apiCallError } from "../../redux/actions/apiStatusActions"; export function loadSystemDateTime() { - return function (dispatch) { + return async function (dispatch) { dispatch(beginApiCall()); - return api - .getSystemDateTime() - .then((data) => { - dispatch({ type: types.LOAD_SYSTEM_DATETIME_SUCCESS, payload: data }); - }) - .catch((error) => { - dispatch(apiCallError(error)); - throw error; - }); + try { + const data = await api.getSystemDateTime(); + dispatch({ type: types.LOAD_SYSTEM_DATETIME_SUCCESS, payload: data }); + } catch (error) { + dispatch(apiCallError(error)); + throw error; + } }; } diff --git a/src/features/system/api.js b/src/features/system/api.js index 0f31ead..4f939ac 100644 --- a/src/features/system/api.js +++ b/src/features/system/api.js @@ -1,6 +1,9 @@ import { handleResponse, handleError } from "../../api/apiUtils"; const baseUrl = process.env.REVERSE_PROXY_API_URL + "/system"; -export function getSystemDateTime() { - return fetch(`${baseUrl}/datetime`).then(handleResponse).catch(handleError); -} +const getSystemDateTime = () => + fetch(`${baseUrl}/datetime`).then(handleResponse).catch(handleError); + +export default { + getSystemDateTime +};