0

I have below piece of code

export const getCartFromApi = () => {
  try {
    const postData = { meta: {}, data: { cartId } };
    const apiResponse = HttpService.post(`${getSecureBaseUrl()}` + apiUrls.getCartDetailsurl, postData);
    Promise.all([apiResponse]).then((res) => {
      console.log('api response', res);
      if (res[0] && res[0].data && res[0].status === 200) {
        store.dispatch({ type: Constants.GET_CART_SUCCESS, response: res[0].data });
        setTimeout(() => {
          hideLoader(store.dispatch);
        }, 2000);
        return res;
      }
      setTimeout(() => {
        hideLoader(store.dispatch);
      }, 3000);
      return res;
    });
  } catch (error) {
  }
};

When im trying to access getCartfrom api is says undefined.

What am I missing here?

valli
  • 103
  • 2
  • 11
  • You do not return anything from `getCartFromApi` so the result of calling `getCartFromApi` is `undefined`. (You only return something from `then((res) => { … }) `) – t.niese Jun 03 '21 at 07:45
  • 1
    Why `Promise.all([apiResponse])` instead of just `apiResponse`? – Sebastian Simon Jun 03 '21 at 07:48

0 Answers0