From dccfecdd269a0707f5b8d04542bac86ca09b006f Mon Sep 17 00:00:00 2001
From: FORESTIER Fabien <fabien.forestier@soprasteria.com>
Date: Fri, 18 Oct 2019 11:11:25 +0200
Subject: [PATCH] Make sure the app still starts if the user initialization
 fails

---
 src/app/app.module.ts      | 18 +++++++++++++-----
 src/i18n/traductions.fr.ts |  1 +
 src/i18n/traductions.ts    |  1 +
 3 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/src/app/app.module.ts b/src/app/app.module.ts
index 46eeeb25..163dc5c2 100644
--- a/src/app/app.module.ts
+++ b/src/app/app.module.ts
@@ -10,17 +10,25 @@ import { EditorialisationModule } from './editorialisation/editorialisation.modu
 import { Angulartics2Module } from 'angulartics2';
 import { UserModule } from './user/user.module';
 import { UserService } from './user/services';
-import { AppConfigService } from './core/services';
+import { AppConfigService, NotificationService } from './core/services';
+import { timeout } from 'rxjs/operators';
+import { notificationMessages } from '../i18n/traductions';
 
 // Function used by APP_INITIALIZER before the app start: init user info / statut (expect a promise)
-export function initUserService(authService: UserService) {
+export function initUserService(authService: UserService, notificationService: NotificationService) {
   return (): Promise<any> => {
     return new Promise((resolve, reject) => {
-      authService.initializeService().subscribe(
+      authService.initializeService().pipe(timeout(3000)).subscribe(
         () => {
           resolve();
         },
-        () => {
+        (err) => {
+          if (err.status !== 401) {
+            notificationService.notify({
+              type: 'error',
+              message: notificationMessages.userInfo.userInit,
+            });
+          }
           resolve();
         });
     });
@@ -61,7 +69,7 @@ export function initAppConfig(appConfigService: AppConfigService) {
     {
       provide: APP_INITIALIZER,
       useFactory: initUserService,
-      deps: [UserService],
+      deps: [UserService, NotificationService],
       multi: true,
     },
   ],
diff --git a/src/i18n/traductions.fr.ts b/src/i18n/traductions.fr.ts
index 17b49f08..9b158ebe 100644
--- a/src/i18n/traductions.fr.ts
+++ b/src/i18n/traductions.fr.ts
@@ -68,6 +68,7 @@ export const notificationMessages = {
     userPasswordUpdated: 'Votre mot de passe a été mis à jour.',
     wrongOldPassword: 'Il semblerait que l\'ancien mot de passe saisi soit incorrect.',
     errorDeletingAccount: 'Une erreur est survenue lors de la suppression de votre compte.',
+    userInit: 'Une erreur est survenue lors de la récupération des informations de votre compte.',
   },
   general: {
     failedDownloadFile: 'Désolé, il n\'a pas été possible de télécharger le fichier. Essayez plus tard !',
diff --git a/src/i18n/traductions.ts b/src/i18n/traductions.ts
index 9873793e..307b72d9 100644
--- a/src/i18n/traductions.ts
+++ b/src/i18n/traductions.ts
@@ -67,6 +67,7 @@ export const notificationMessages = {
     failedToUpdateUserPassword: 'An error occured while updating your password.',
     wrongOldPassword: 'Looks like the old password entered is incorrect.',
     errorDeletingAccount: 'An error occured while deleting your account.',
+    userInit: 'An error occured while retrieving your account information.',
   },
   general: {
     failedDownloadFile: 'Sorry, it was not possible to download the file. Try later !',
-- 
GitLab