Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potentially unhandled rejection [15] Error #1

Open
Bomberlt opened this issue Jan 16, 2017 · 1 comment
Open

Potentially unhandled rejection [15] Error #1

Bomberlt opened this issue Jan 16, 2017 · 1 comment

Comments

@Bomberlt
Copy link

Bomberlt commented Jan 16, 2017

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.

@thaerlabs
Copy link
Owner

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants