webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherActions.js in foreman_ansible-6.1.1 vs webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherActions.js in foreman_ansible-6.2.0

- old
+ new

@@ -19,31 +19,31 @@ inheritedRoleIds, resourceId, resourceName, pagination, search -) => dispatch => { +) => async dispatch => { dispatch({ type: ANSIBLE_ROLES_REQUEST }); const params = { ...propsToSnakeCase(pagination || {}), ...(search || {}), ...propsToSnakeCase({ resourceId, resourceName }), }; - return api - .get(url, {}, params) - .then(({ data }) => - dispatch({ - type: ANSIBLE_ROLES_SUCCESS, - payload: { - initialAssignedRoles, - inheritedRoleIds, - ...propsToCamelCase(data), - }, - }) - ) - .catch(error => dispatch(errorHandler(ANSIBLE_ROLES_FAILURE, error))); + try { + const res = await api.get(url, {}, params); + return dispatch({ + type: ANSIBLE_ROLES_SUCCESS, + payload: { + initialAssignedRoles, + inheritedRoleIds, + ...propsToCamelCase(res.data), + }, + }); + } catch (error) { + return dispatch(errorHandler(ANSIBLE_ROLES_FAILURE, error)); + } }; const errorHandler = (msg, err) => { const error = { errorMsg: 'Failed to fetch Ansible Roles from server.',