ฉันมีคำสัญญามากมายที่ฉันแก้ไขด้วย Promise.all(arrayOfPromises);
ฉันไปเพื่อดำเนินการต่อสัญญาโซ่ ดูเหมือนอะไรแบบนี้
existingPromiseChain = existingPromiseChain.then(function() {
  var arrayOfPromises = state.routes.map(function(route){
    return route.handler.promiseHandler();
  });
  return Promise.all(arrayOfPromises)
});
existingPromiseChain = existingPromiseChain.then(function(arrayResolved) {
  // do stuff with my array of resolved promises, eventually ending with a res.send();
});
ฉันต้องการเพิ่มคำสั่ง catch เพื่อจัดการแต่ละสัญญาในกรณีที่เกิดข้อผิดพลาด แต่เมื่อฉันลองPromise.allส่งคืนข้อผิดพลาดแรกที่พบ (ไม่สนใจส่วนที่เหลือ) จากนั้นฉันไม่สามารถรับข้อมูลจากส่วนที่เหลือของสัญญาใน อาร์เรย์ (ที่ไม่ผิดพลาด)
ฉันพยายามทำบางสิ่งเช่น ..
existingPromiseChain = existingPromiseChain.then(function() {
      var arrayOfPromises = state.routes.map(function(route){
        return route.handler.promiseHandler()
          .then(function(data) {
             return data;
          })
          .catch(function(err) {
             return err
          });
      });
      return Promise.all(arrayOfPromises)
    });
existingPromiseChain = existingPromiseChain.then(function(arrayResolved) {
      // do stuff with my array of resolved promises, eventually ending with a res.send();
});
แต่นั่นก็ไม่ได้แก้ไข
ขอบคุณ!
-
แก้ไข:
สิ่งที่คำตอบด้านล่างนี้พูดนั้นเป็นความจริงอย่างสมบูรณ์รหัสก็ผิดปกติเนื่องจากเหตุผลอื่น ในกรณีที่ใครสนใจนี่เป็นคำตอบที่ฉันลงเอยด้วย ...
โหนดเซิร์ฟเวอร์ Express
serverSidePromiseChain
    .then(function(AppRouter) {
        var arrayOfPromises = state.routes.map(function(route) {
            return route.async();
        });
        Promise.all(arrayOfPromises)
            .catch(function(err) {
                // log that I have an error, return the entire array;
                console.log('A promise failed to resolve', err);
                return arrayOfPromises;
            })
            .then(function(arrayOfPromises) {
                // full array of resolved promises;
            })
    };
API Call (สาย route.async)
return async()
    .then(function(result) {
        // dispatch a success
        return result;
    })
    .catch(function(err) {
        // dispatch a failure and throw error
        throw err;
    });
วาง.catchไว้Promise.allก่อนหน้า.thenดูเหมือนว่าจะมีวัตถุประสงค์ในการจับข้อผิดพลาดใด ๆ จากสัญญาเดิม แต่แล้วกลับอาร์เรย์ทั้งหมดไปยังถัดไป.then
ขอบคุณ!
.then(function(data) { return data; })สามารถละเว้นได้อย่างสมบูรณ์
                thenหรือcatchตัวจัดการและมีข้อผิดพลาดเกิดขึ้นภายใน โดยวิธีนี้โหนดนี้หรือไม่