Skip to content
Snippets Groups Projects
Commit 37425d06 authored by mathias.chouet's avatar mathias.chouet
Browse files

Chargement de session: avertissement en cas d'erreur non fatale

parent 7d1a945b
No related branches found
No related tags found
No related merge requests found
...@@ -466,12 +466,18 @@ export class AppComponent implements OnInit, OnDestroy, Observer { ...@@ -466,12 +466,18 @@ export class AppComponent implements OnInit, OnDestroy, Observer {
if (result.emptySession) { if (result.emptySession) {
this.doEmptySession(); this.doEmptySession();
} }
this.formulaireService.loadSession(result.file, result.calculators).catch((err) => { this.formulaireService.loadSession(result.file, result.calculators)
this.notificationsService.notify(this.intlService.localizeText("ERROR_LOADING_SESSION")); .then((data) => {
console.error("error loading session - ", err); if (data.hasErrors) {
// rollback to ensure session is clean this.notificationsService.notify(this.intlService.localizeText("ERROR_PROBLEM_LOADING_SESSION"), 3500);
this.doEmptySession(); }
}); })
.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();
});
} }
}); });
} }
......
...@@ -513,7 +513,7 @@ export class FormulaireService extends Observable { ...@@ -513,7 +513,7 @@ export class FormulaireService extends Observable {
* @param f fichier session * @param f fichier session
* @param formInfos infos sur les modules de calcul @see DialogLoadSessionComponent.calculators * @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 { try {
const s = await this.readSingleFile(f); const s = await this.readSingleFile(f);
const uids: string[] = []; const uids: string[] = [];
...@@ -522,7 +522,8 @@ export class FormulaireService extends Observable { ...@@ -522,7 +522,8 @@ export class FormulaireService extends Observable {
uids.push(fi.uid); 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 each new Nub, create the related form, set its title
for (let i = 0; i < newNubs.length; i++) { for (let i = 0; i < newNubs.length; i++) {
const nn = newNubs[i]; const nn = newNubs[i];
...@@ -534,10 +535,13 @@ export class FormulaireService extends Observable { ...@@ -534,10 +535,13 @@ export class FormulaireService extends Observable {
await this.loadLocalisation(nn.nub.calcType); await this.loadLocalisation(nn.nub.calcType);
await this.createFormulaire(nn.nub.calcType, nn.nub, title); // await guarantees loading order await this.createFormulaire(nn.nub.calcType, nn.nub, title); // await guarantees loading order
} }
return s; // forward errors
return {
hasErrors: res.hasErrors
};
} catch (err) { } catch (err) {
// forward errors to caller, to avoid "Uncaught (in promise)" // forward errors to caller to avoid "Uncaught (in promise)"
throw err; throw err;
} }
} }
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
"ERROR_PARAMDEF_VALUE_UNDEFINED": "value of '%symbol%' parameter is undefined", "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_INTERVAL_BOUNDS": "invalid %minValue%/%maxValue% min/max boundaries for 'interval' parameter definition domain",
"ERROR_PARAMDOMAIN_INVALID": "parameter '%symbol%: non supported '%domain%' 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_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_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)", "ERROR_REMOUS_PENTE_FORTE": "The water line slope is too steep at abscissa %x% m (the discretisation step should be reduced)",
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
"ERROR_PARAMDEF_VALUE_UNDEFINED": "La valeur du paramètre %symbol% n'est pas définie", "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_INTERVAL_BOUNDS": "Les bornes (%minValue%/%maxValue%) de l'intervalle sont incorrectes",
"ERROR_PARAMDOMAIN_INVALID": "Paramètre '%symbol%'&nbsp;: le domaine de définition '%domain%' est incorrect", "ERROR_PARAMDOMAIN_INVALID": "Paramètre '%symbol%'&nbsp;: 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&nbsp;: pas de calcul possible depuis l'amont", "ERROR_REMOUS_PAS_CALCUL_DEPUIS_AMONT": "Condition limite amont > Hauteur critique&nbsp;: pas de calcul possible depuis l'amont",
"ERROR_REMOUS_PAS_CALCUL_DEPUIS_AVAL": "Condition limite aval < Hauteur critique&nbsp;: pas de calcul possible depuis l'aval", "ERROR_REMOUS_PAS_CALCUL_DEPUIS_AVAL": "Condition limite aval < Hauteur critique&nbsp;: 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)", "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)",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment