axios-cancel icon indicating copy to clipboard operation
axios-cancel copied to clipboard

Potentially unhandled rejection [15] Error

Open Bomberlt opened this issue 8 years ago • 1 comments

When using axios-cancel and http response is 401 error (I think the same for all 4xx) "Potentially unhandled rejection [15] Error" occurs.

The problem that error does not get to the .catch():

return axios({
                url: prepareURL(url),
                method: 'post',
                headers: prepareAuthHeader(),
                data: params,
                requestId: requestId
            }).then((response) => response.data)
            .catch(function(thrown){  // 400 Error is not going here
                if (axios.isCancel(thrown)){
                    console.log('Request canceled', thrown.message);
                } else{
                    when.reject(thrown);
                }
            });

axio-cancel debug log: adding request 1 index.js:1 adding request '1484560946801' xhr.js:175 POST http://..../... 401 (Unauthorized) dispatchXhrRequest @ xhr.js:175 xhrAdapter @ xhr.js:12 dispatchRequest @ dispatchRequest.js:52 unhandledRejection.js:23 Potentially unhandled rejection [1] Error: Request failed with status code 401 at createError (http://..../index-1484560715206.js:24790:16) at settle (http://..../index-1484560715206.js:24762:13) at XMLHttpRequest.handleLoad (http://..../index-1484560715206.js:24638:8) (anonymous) @ unhandledRejection.js:23 report @ unhandledRejection.js:50 flush @ unhandledRejection.js:72 index.js:1 removing request 1

P.S. I'm new to javascript so maybe it could be my mistake, I could add more context if needed.

Bomberlt avatar Jan 16 '17 10:01 Bomberlt

Hi @Bomberlt, I see you're using return when using axios(). You're handling the promise in the .then and catch blocks inside the function. Are you attaching another then or catch on the returned value?

example

// some api service

function getList() {
  return axios.get('http://google.com');
}

function init() {
  getList()
    .then()
    .catch();
}

Maybe the issue happens when doing

// some api service

function getList() {
  return axios.get('http://google.com')
    .then()
    .catch();
}
}

function init() {
  getList()
    .then()
    .catch();
}

Can you please post a more clear example?

thaerlabs avatar Jan 31 '17 13:01 thaerlabs