0

Is it possible to setTimeOut the response of the following axios call?

export function getMetricsByContent(metricsParams) {
    console.log('metricsParams: ', metricsParams);
    return (dispatch) => {
        return axios.post(`/rbac/aa/reads/getReport`, metricsParams).then((response) => {
            console.log('metricsApiResponse: ', response);
            if (response.status !== 200) {
                throw Error(response.statusText);
            }
            return response;
        }).then((response) => {
            if (response) {
                return response.data.msg;
            } else {
                return "No content available";
            }

        })
            .catch((err) => {return err});
        };

}
Prem
  • 4,657
  • 12
  • 38
  • 75
  • you looking for `setTimeout(() => { console.log('Our data is fetched'); return response.data.msg; }, 1000)` – IftekharDani Nov 06 '18 at 07:28
  • Why is your action creator returning something and not dispatching anything? – HMR Nov 06 '18 at 07:42
  • 1
    You could use [Promise.race](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race) and race the request with a [delay function that's described here](https://stackoverflow.com/a/39538518/1641941). The request cannot be cancelled once requested but you can just stop waiting for it. – HMR Nov 06 '18 at 07:47

0 Answers0