Unhandle Promise отклонение внутри блока try - PullRequest
0 голосов
/ 12 ноября 2018

У меня возникают трудности с пониманием того, почему приведенный ниже код выдает Предупреждение об отказе в необработанном обещании :

router.post('/stampaClasse/:as(20[0-9][0-9]/[0-9][0-9])/:classe([1-8])',async function (req,res,next){

  const sezioni = await Classi.getSezioniFromAnnoScolasticoAndClasse(req.params.as,req.params.classe);
  let options = {
    semestre: req.body.semestre,
    fontSize: req.body.fontSize,
    textColor: '#515151',
    gridColor: '#bec0be',
    corDidattico:{
      titolo:'prof.',
      nome:'Roberto',
      cognome:'Dalema'
    }
  }
  let newPDF = new pdfKit();
  try{
    for(sezione of sezioni){

      const idStudentiPromise = Classi.getStudentiFromAnnoScolasticoAndClasseAndSezione(req.params.as,req.params.classe,sezione)
      const materiePromise = Classi.getMaterieSezione(req.params.as,req.params.classe,sezione)
      const infoStudentiPromise = Promise.all(  Studenti.getInfoStudentiById(await idStudentiResults) )


      let classe = {
        annoScolastico: req.params.as,
        classe : req.params.classe,
        sezione: sezione,
        materie: await materiePromise,
        studenti: await infoStudentiPromise
      }
      for(studente of classe.studenti){
        studente.pagelleMateriePromises = classe.materie.map(async m=>Pagelle.getPagellaFromStudente(classe.annoScolastico,classe.classe,classe.sezione,m,studente.id));
      }
      for(studente of classe.studenti){
        studente.pagelleMaterie = await Promise.all(studente.pagelleMateriePromises)
        addHeader(newPDF,studente,classe,options);
        addPagelleSemestre(newPDF,studente,classe,options);
        addFooter(newPDF,studente,classe,options);
      }
    }

    newPDF.pipe(res);
    newPDF.end();
  }
  catch(err){
    next(err)
  }
});  

Ошибка возникает несколько раз, и это вызвано тем, что в строке

const infoStudentiPromise = Promise.all(  Studenti.getInfoStudentiById(await idStudentiResults) )

idStudentiResults alredy возвращает Promise.all ()

рассматривает того, что вызывает ошибку. Я хотел бы знать, почему в ней говорится, что ошибка не обрабатывается. Это попытка поймать не смеяться

1 Ответ

0 голосов
/ 12 ноября 2018

Promise.all необходимо получить массив обещаний в качестве параметра.Убедитесь, что Module.getInfo(ids) возвращает это.

...