Home > Blockchain >  Calling then twice that conains response on axios
Calling then twice that conains response on axios

Time:01-17

How to call then twice with same response object?

function a() {
  return axios.get('/foo').then(function(resp){
    // do something with resp, eg. if 401 then force local state to logout
  })
}

// the caller:
a().then(function(resp) {
  // not called, I want same resp, not just data
}).catch(console.log).then(clearLoadingBar)

CodePudding user response:

If you want your promise to return resp, you will need return it:

return axios.get('/foo').then(function(resp){
  // do something with resp, eg. if 401 then force local state to logout
  return resp;
});
  • Related