我正在尝试查看如何在 javascript 中处理并发异步请求,您是否知道使用 axios 获取成功请求结果的方法,即使请求失败也是如此?如果不是,您将如何处理这种情况?
var axios = require( 'axios' )
var options = [{
baseURL: 'https://some-base-url'
, url: '/some-path&key=some-key'
, method: 'post'
, data: 'some-data'
}, {
baseURL: 'https://some-base-url'
, url: '/some-path&key=some-key'
, method: 'post'
, data: 'some-other-data'
}, {
baseURL: 'https://some-base-url'
, url: '/some-path&key=WRONG-KEY' // WRONG KEY
, method: 'post'
, data: 'some-other-data'
}]
axios.all([
axios.request(options[ 0 ])
, axios.request(options[ 1 ])
, axios.request(options[ 2 ])
]).then(axios.spread(function (res1, res2, res3) {
// when all requests successful
}))
.catch(function(res) {
// third request was unsuccessful (403) but no way to get
// the results of the two previous successful ones?
console.log( res )
})