diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 49857e2382267a1294d544c77d242aca23856207..abc82023600296b93d6dee63d843ab6a60b4fdb3 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -438,7 +438,12 @@ export class AppComponent implements OnInit, OnDestroy, Observer { if (result.emptySession) { this.doEmptySession(); } - this.formulaireService.loadSession(result.file, result.calculators); + 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(); + }); } }); } diff --git a/src/app/services/formulaire/formulaire.service.ts b/src/app/services/formulaire/formulaire.service.ts index 655be967df308c8a05661b9010b9dbdd067218d2..47e7941dc2281e62ca151aa06e9bdcb8e22ce55b 100644 --- a/src/app/services/formulaire/formulaire.service.ts +++ b/src/app/services/formulaire/formulaire.service.ts @@ -454,8 +454,8 @@ export class FormulaireService extends Observable { * @param f fichier session * @param formInfos infos sur les modules de calcul @see DialogLoadSessionComponent.calculators */ - public loadSession(f: File, formInfos: any[]) { - this.readSingleFile(f).then(s => { + public loadSession(f: File, formInfos: any[]): Promise<any> { + return this.readSingleFile(f).then(s => { const uids: string[] = []; formInfos.forEach((fi) => { if (fi.selected) { @@ -472,6 +472,7 @@ export class FormulaireService extends Observable { this.createFormulaire(nn.nub.calcType, nn.nub, title); }); }).catch(err => { + // forward errors to caller, to avoid "Uncaught (in promise)…" throw err; }); } diff --git a/src/app/services/notifications/notifications.service.ts b/src/app/services/notifications/notifications.service.ts index 9caf0d7ffb1a7832f671261980764a7e30a29046..bb404d860861d53be39c5a7b7a765004821f472d 100644 --- a/src/app/services/notifications/notifications.service.ts +++ b/src/app/services/notifications/notifications.service.ts @@ -20,7 +20,7 @@ export class NotificationsService { } /** Push a notification and display it as soon as possible */ - public notify(message: string, duration: number, action: string = "OK") { + public notify(message: string, duration: number = 2000, action: string = "OK") { this.notifications.push({ message: message, duration: duration, diff --git a/src/locale/messages.en.json b/src/locale/messages.en.json index 1f84ea625989c17e10571b2eefaf303930eeecdf..ddccf44b31dd34403073bce22ef0b24fc52389ae 100644 --- a/src/locale/messages.en.json +++ b/src/locale/messages.en.json @@ -10,6 +10,7 @@ "ERROR_INTERVAL_OUTSIDE": "Interval: value %value% is outside of %interval", "ERROR_INTERVAL_UNDEF": "Interval: invalid 'undefined' value", "ERROR_INVALID_AT_POSITION": "Position %s:", + "ERROR_LOADING_SESSION": "Unable to load session", "ERROR_MINMAXSTEP_MAX": "Value is not in ]%s,%s]", "ERROR_MINMAXSTEP_MIN": "Value is not in [%s,%s[", "ERROR_MINMAXSTEP_STEP": "Value is not in %s", diff --git a/src/locale/messages.fr.json b/src/locale/messages.fr.json index 77620375a20a96f6625f4cb3df158ea4ee16bf05..6549da552af935f90200ffe790c724f8a0075f9f 100644 --- a/src/locale/messages.fr.json +++ b/src/locale/messages.fr.json @@ -10,6 +10,7 @@ "ERROR_INTERVAL_OUTSIDE": "Interval : la valeur %value% est hors de l'intervalle %interval", "ERROR_INTERVAL_UNDEF": "Interval : valeur 'undefined' incorrecte", "ERROR_INVALID_AT_POSITION": "Position %s :", + "ERROR_LOADING_SESSION": "Impossible de charger la session", "ERROR_MINMAXSTEP_MAX": "La valeur n'est pas dans ]%s,%s]", "ERROR_MINMAXSTEP_MIN": "La valeur n'est pas dans [%s,%s[", "ERROR_MINMAXSTEP_STEP": "La valeur n'est pas dans %s",