Commit 6de6f672 authored by FORESTIER Fabien's avatar FORESTIER Fabien Committed by ncastejon
Browse files

Make sure the app still starts if the user initialization fails

parent 46146c11
......@@ -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,
},
],
......
......@@ -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 !',
......
......@@ -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 !',
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment