1

I am making an axios GET request on IE and both the code within the then and catch callbacks are both being executed. Firstly it is successful, and then it runs into the error block.

This is only happening on Internet Explorer. Works fine on Chrome, safari and firefox.

Can anyone spot a silly error I may be making.

export const getData = () => {

    return dispatch => {

        dispatch(getDataRequest());

        // This appears once in the console
        console.log('CALLED');

        axios.get(`${cmsPath}/casinocms.cache.json`).then(res => {

            // Firstly I see this in the console
            console.log('NO ERROR!');

            dispatch(getDataSuccess(res.data));

        }).catch(err => {

            // I then also see this message in the console, 
            // following the message above

            console.log('ERROR!')
            dispatch(getDataError(err));

        });

    };
};
  • 2
    It would mean that `dispatch(getDataSuccess(res.data));` throws an exception. Don't you see what `err` is? – Bergi Aug 31 '17 at 13:44
  • Have a look at the [difference between `.then(…, …)` and `.then(…).catch(…)`](https://stackoverflow.com/q/24662289/1048572) – Bergi Aug 31 '17 at 13:45
  • What is `Promise.reject(err)` doing there? That only causes an unhandled rejection. – Bergi Aug 31 '17 at 13:45
  • @Bergi I put that in as an attempt to get this to work. Have removed again. The `getDataSuccess` is just an action that is sent to the reducer. Not sure how this would throw an error. And as i said this is just on IE –  Aug 31 '17 at 13:46
  • possible duplicate of [Detecting errors in promise chain](https://stackoverflow.com/questions/42381446/detecting-fetch-typeerrors-in-promise-chain)? – Bergi Aug 31 '17 at 13:47
  • I don't know how or why this would throw an error either. What debugging have you done? What *is* the error? – Bergi Aug 31 '17 at 13:49
  • @Bergi I have been debugging for the last 5 hours. Have tried everything. Have only just realised that it was calling both then and catch blocks. –  Aug 31 '17 at 13:54
  • No other results in 5 hours of debugging? Have you at least done `console.log(err)`? – Bergi Aug 31 '17 at 13:58
  • @Bergi this was the question from earlier that no one could answer - https://stackoverflow.com/questions/45978423/issue-with-axios-unhandled-promise-internet-explorer?noredirect=1#comment78916690_45978423 –  Aug 31 '17 at 14:02

0 Answers0