У меня 6 асинхронных запросов.Если один из них выдает ошибку, возвращает 404, другие запросы тоже не работают.Я использую async.parallel
, чтобы сделать эти запросы.Я пытаюсь заставить работать другие запросы, когда один из них терпит неудачу.Но я не смог сделать это.
Вот мой код:
async.parallel({
request1: async (callback) => {
const [err, result] = await to(this.$store.dispatch('myAction1', {
id: this.$route.params.id,
}));
callback(err, result);
},
request2: async (callback) => {
const [err, result] = await to(this.$store.dispatch('myAction2', {
params: {
id: this.$route.params.id,
page: this.page,
size: this.size,
},
}));
callback(err, result);
},
request3: async (callback) => {
const [err, result] = await to(this.$store.dispatch('myAction3', {
data: {
filters: this.inputs.filters,
projections: this.inputs.projections,
showTotalCount: this.inputs.showTotalCount,
},
params: {
page: this.page,
size: this.size,
},
}));
callback(err, result);
},
request4: async (callback) => {
const [err, result] = await to(this.$store.dispatch('myAction4'));
callback(err, result);
},
request5: async (callback) => {
const [err, result] = await to(this.$store.dispatch('myAction5', {
id: this.$route.params.id,
}));
callback(err, result);
},
request6: async (callback) => {
const [err, result] = await to(this.$store.dispatch('myAction6', {
params: {
id: this.$route.params.id,
},
}));
callback(err, result);
},
}, (err, results) => {
if (err) {
// Show error message when one of them fails
}
// doing something when all requests success and hide the page loader.
this.hidePageLoader();
});
Этот код всегда показывает загрузчик страницы, если один из этих запросов возвращает 404, я хочу передать неудавшийся запрос как null
к моему results
объекту или вернуть другие результаты без неудачного запроса в results
объекте.Как я могу сделать это правильно