I have the following setup where I am trying to make a call to a function which returns a Promise
, which in turn has a Promise.all()
call to make an indefinite number of axios.post()
calls. I tried using axios.all()
and axios.spread(...responses)
, but no luck. I've also tried a number of examples posted to SO from experienced users. But still no luck.
It's worth noting that the calls are being made, it's just that the responses being returned are undefined.
The function being called is the following:
createSurveyResult(surveyResults) {
let token = Vue.prototype.$auth.getLocalStorage(`${this.activeUser.uuid)_{process.env.NODE_ENV}_ACCESS_TOKEN`)
if (token) {
axiosModified.defaults.headers.common['Authorization'] = `Bearer ${token}`
}
return new Promise(resolve => {
let promiseArray = surveyResults.map(payload => {
axiosModified.post('/feedback/results/', payload)
})
Promise.all(promiseArray).then(responses => {
responses.forEach(res => console.log(res))
console.log('submitted all axios calls');
resolve(responses)
}).catch(error => {
resolve(error.response)
})
})
}
Which is being called as:
this.$surveys.createSurveyResult(surveyResults).then((responses) => {
console.log(responses)
});
Yet, both the console.log(res)
res objects return are undefined within the Promise.all()
, the console.log('submitted all
axios calls');
is being called, and the responses from the then() callback are returned as:
I'm wondering what I am doing wrong here?