diff --git a/src/app/app.component.ts b/src/app/app.component.ts index ae8842a56344708e1d3f89cf5aba1d823ccc98ce..c4ebf521a2e0dde99280d09f2ca496b2bda6bbb4 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -466,12 +466,18 @@ export class AppComponent implements OnInit, OnDestroy, Observer { if (result.emptySession) { this.doEmptySession(); } - this.formulaireService.loadSession(result.file, result.calculators).catch((err) => { - this.notificationsService.notify(this.intlService.localizeText("ERROR_LOADING_SESSION")); - console.error("error loading session - ", err); - // rollback to ensure session is clean - this.doEmptySession(); - }); + this.formulaireService.loadSession(result.file, result.calculators) + .then((data) => { + if (data.hasErrors) { + this.notificationsService.notify(this.intlService.localizeText("ERROR_PROBLEM_LOADING_SESSION"), 3500); + } + }) + .catch((err) => { + this.notificationsService.notify(this.intlService.localizeText("ERROR_LOADING_SESSION"), 3500); + console.error("error loading session - ", err); + // rollback to ensure session is clean + this.doEmptySession(); + }); } }); } diff --git a/src/app/services/formulaire/formulaire.service.ts b/src/app/services/formulaire/formulaire.service.ts index 642f163ad3cbdc98f6e60bf69d8047e9f25fda31..116bf898f4a512973707a8682977e0f058bbea16 100644 --- a/src/app/services/formulaire/formulaire.service.ts +++ b/src/app/services/formulaire/formulaire.service.ts @@ -513,7 +513,7 @@ export class FormulaireService extends Observable { * @param f fichier session * @param formInfos infos sur les modules de calcul @see DialogLoadSessionComponent.calculators */ - public async loadSession(f: File, formInfos: any[]): Promise<any> { + public async loadSession(f: File, formInfos: any[]): Promise<{ hasErrors: boolean }> { try { const s = await this.readSingleFile(f); const uids: string[] = []; @@ -522,7 +522,8 @@ export class FormulaireService extends Observable { uids.push(fi.uid); } }); - const newNubs = Session.getInstance().unserialise(s, uids); + const res = Session.getInstance().unserialise(s, uids); + const newNubs = res.nubs; // for each new Nub, create the related form, set its title for (let i = 0; i < newNubs.length; i++) { const nn = newNubs[i]; @@ -534,10 +535,13 @@ export class FormulaireService extends Observable { await this.loadLocalisation(nn.nub.calcType); await this.createFormulaire(nn.nub.calcType, nn.nub, title); // await guarantees loading order } - return s; + // forward errors + return { + hasErrors: res.hasErrors + }; } catch (err) { - // forward errors to caller, to avoid "Uncaught (in promise)…" + // forward errors to caller to avoid "Uncaught (in promise)" throw err; } } diff --git a/src/locale/messages.en.json b/src/locale/messages.en.json index 2b6aa4f811d1d397ffd9880ac45911db69c6cd64..2f56f60c7d47d36b8b1c5e675ae4270ecaef0222 100644 --- a/src/locale/messages.en.json +++ b/src/locale/messages.en.json @@ -29,6 +29,7 @@ "ERROR_PARAMDEF_VALUE_UNDEFINED": "value of '%symbol%' parameter is undefined", "ERROR_PARAMDOMAIN_INTERVAL_BOUNDS": "invalid %minValue%/%maxValue% min/max boundaries for 'interval' parameter definition domain", "ERROR_PARAMDOMAIN_INVALID": "parameter '%symbol%: non supported '%domain%' definition domain", + "ERROR_PROBLEM_LOADING_SESSION": "Session loaded, with errors", "ERROR_REMOUS_PAS_CALCUL_DEPUIS_AMONT": "Upstream boundary condition < Critical elevation: no possible calculation from upstream", "ERROR_REMOUS_PAS_CALCUL_DEPUIS_AVAL": "Downstream boundary condition < Critical elevation: no possible calculation from downstream", "ERROR_REMOUS_PENTE_FORTE": "The water line slope is too steep at abscissa %x% m (the discretisation step should be reduced)", diff --git a/src/locale/messages.fr.json b/src/locale/messages.fr.json index ba8010d4d05089b605b225fd482ecfa2f0e79965..d18bb02e588a8c02aebc6f2eb6d7c4a405e79391 100644 --- a/src/locale/messages.fr.json +++ b/src/locale/messages.fr.json @@ -29,6 +29,7 @@ "ERROR_PARAMDEF_VALUE_UNDEFINED": "La valeur du paramètre %symbol% n'est pas définie", "ERROR_PARAMDOMAIN_INTERVAL_BOUNDS": "Les bornes (%minValue%/%maxValue%) de l'intervalle sont incorrectes", "ERROR_PARAMDOMAIN_INVALID": "Paramètre '%symbol%' : le domaine de définition '%domain%' est incorrect", + "ERROR_PROBLEM_LOADING_SESSION": "Session chargée, avec des erreurs", "ERROR_REMOUS_PAS_CALCUL_DEPUIS_AMONT": "Condition limite amont > Hauteur critique : pas de calcul possible depuis l'amont", "ERROR_REMOUS_PAS_CALCUL_DEPUIS_AVAL": "Condition limite aval < Hauteur critique : pas de calcul possible depuis l'aval", "ERROR_REMOUS_PENTE_FORTE": "La pente de la ligne d'eau est trop forte à l'abscisse %x% m (il faudrait réduire le pas de discrétisation)",