Skip to content
Snippets Groups Projects
Commit dccfecdd authored by FORESTIER Fabien's avatar FORESTIER Fabien
Browse files

Make sure the app still starts if the user initialization fails

parent 50d2123c
Branches
Tags
1 merge request!53Version 2.3.2
Pipeline #1783 passed
...@@ -10,17 +10,25 @@ import { EditorialisationModule } from './editorialisation/editorialisation.modu ...@@ -10,17 +10,25 @@ import { EditorialisationModule } from './editorialisation/editorialisation.modu
import { Angulartics2Module } from 'angulartics2'; import { Angulartics2Module } from 'angulartics2';
import { UserModule } from './user/user.module'; import { UserModule } from './user/user.module';
import { UserService } from './user/services'; 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) // 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 (): Promise<any> => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
authService.initializeService().subscribe( authService.initializeService().pipe(timeout(3000)).subscribe(
() => { () => {
resolve(); resolve();
}, },
() => { (err) => {
if (err.status !== 401) {
notificationService.notify({
type: 'error',
message: notificationMessages.userInfo.userInit,
});
}
resolve(); resolve();
}); });
}); });
...@@ -61,7 +69,7 @@ export function initAppConfig(appConfigService: AppConfigService) { ...@@ -61,7 +69,7 @@ export function initAppConfig(appConfigService: AppConfigService) {
{ {
provide: APP_INITIALIZER, provide: APP_INITIALIZER,
useFactory: initUserService, useFactory: initUserService,
deps: [UserService], deps: [UserService, NotificationService],
multi: true, multi: true,
}, },
], ],
......
...@@ -68,6 +68,7 @@ export const notificationMessages = { ...@@ -68,6 +68,7 @@ export const notificationMessages = {
userPasswordUpdated: 'Votre mot de passe a été mis à jour.', userPasswordUpdated: 'Votre mot de passe a été mis à jour.',
wrongOldPassword: 'Il semblerait que l\'ancien mot de passe saisi soit incorrect.', wrongOldPassword: 'Il semblerait que l\'ancien mot de passe saisi soit incorrect.',
errorDeletingAccount: 'Une erreur est survenue lors de la suppression de votre compte.', 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: { general: {
failedDownloadFile: 'Désolé, il n\'a pas été possible de télécharger le fichier. Essayez plus tard !', 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 = { ...@@ -67,6 +67,7 @@ export const notificationMessages = {
failedToUpdateUserPassword: 'An error occured while updating your password.', failedToUpdateUserPassword: 'An error occured while updating your password.',
wrongOldPassword: 'Looks like the old password entered is incorrect.', wrongOldPassword: 'Looks like the old password entered is incorrect.',
errorDeletingAccount: 'An error occured while deleting your account.', errorDeletingAccount: 'An error occured while deleting your account.',
userInit: 'An error occured while retrieving your account information.',
}, },
general: { general: {
failedDownloadFile: 'Sorry, it was not possible to download the file. Try later !', failedDownloadFile: 'Sorry, it was not possible to download the file. Try later !',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment