From ca38670b4e0e80c420073a5c595dbbe9fbd2d9a3 Mon Sep 17 00:00:00 2001 From: Silke Date: Thu, 8 Sep 2022 11:31:59 +0200 Subject: [PATCH] feat: display an error page if the loading of the server configuration fails --- src/app/core/store/core/error/error.actions.ts | 2 ++ src/app/core/store/core/error/error.reducer.ts | 3 ++- .../core/server-config/server-config.effects.spec.ts | 10 ++++++++++ .../store/core/server-config/server-config.effects.ts | 11 ++++++++++- 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/app/core/store/core/error/error.actions.ts b/src/app/core/store/core/error/error.actions.ts index 1ad6517ae7f..06d96d348da 100644 --- a/src/app/core/store/core/error/error.actions.ts +++ b/src/app/core/store/core/error/error.actions.ts @@ -7,3 +7,5 @@ export const communicationTimeoutError = createAction('[Error] Communication Tim export const serverError = createAction('[Error] Server Error (5xx)', httpError()); export const businessError = createAction('[Error] Business Error', payload<{ error: string }>()); + +export const serverConfigError = createAction('[Error] Load Server Configuration Error', httpError()); diff --git a/src/app/core/store/core/error/error.reducer.ts b/src/app/core/store/core/error/error.reducer.ts index ed77cc0e8d9..c5cf4e468da 100644 --- a/src/app/core/store/core/error/error.reducer.ts +++ b/src/app/core/store/core/error/error.reducer.ts @@ -2,7 +2,7 @@ import { createReducer, on } from '@ngrx/store'; import { HttpError } from 'ish-core/models/http-error/http-error.model'; -import { businessError, communicationTimeoutError, serverError } from './error.actions'; +import { businessError, communicationTimeoutError, serverConfigError, serverError } from './error.actions'; export interface ErrorState { current: HttpError | string; @@ -20,6 +20,7 @@ export const errorReducer = createReducer( serverError, businessError, communicationTimeoutError, + serverConfigError, (state, action): ErrorState => ({ ...state, current: action.payload.error, diff --git a/src/app/core/store/core/server-config/server-config.effects.spec.ts b/src/app/core/store/core/server-config/server-config.effects.spec.ts index a450e72e1c5..541b36771c2 100644 --- a/src/app/core/store/core/server-config/server-config.effects.spec.ts +++ b/src/app/core/store/core/server-config/server-config.effects.spec.ts @@ -8,6 +8,7 @@ import { instance, mock, when } from 'ts-mockito'; import { ConfigurationService } from 'ish-core/services/configuration/configuration.service'; import { CoreStoreModule } from 'ish-core/store/core/core-store.module'; +import { serverConfigError } from 'ish-core/store/core/error'; import { makeHttpError } from 'ish-core/utils/dev/api-service-utils'; import { StoreWithSnapshots, provideStoreSnapshots } from 'ish-core/utils/dev/ngrx-testing'; import { routerTestNavigationAction } from 'ish-core/utils/dev/routing'; @@ -121,5 +122,14 @@ describe('Server Config Effects', () => { expect(effects.loadServerConfig$).toBeObservable(expected$); }); + + it('should map invalid request to action of type serverConfigError', () => { + const action = loadServerConfigFail({ error: makeHttpError({ message: 'invalid' }) }); + const completion = serverConfigError({ error: makeHttpError({ message: 'invalid' }) }); + actions$ = hot('-a-a-a', { a: action }); + const expected$ = cold('-c-c-c', { c: completion }); + + expect(effects.mapToServerConfigError$).toBeObservable(expected$); + }); }); }); diff --git a/src/app/core/store/core/server-config/server-config.effects.ts b/src/app/core/store/core/server-config/server-config.effects.ts index cd83b0feb41..44cd6bdcc3a 100644 --- a/src/app/core/store/core/server-config/server-config.effects.ts +++ b/src/app/core/store/core/server-config/server-config.effects.ts @@ -6,7 +6,8 @@ import { identity } from 'rxjs'; import { concatMap, first, map, switchMap } from 'rxjs/operators'; import { ConfigurationService } from 'ish-core/services/configuration/configuration.service'; -import { mapErrorToAction, whenFalsy } from 'ish-core/utils/operators'; +import { serverConfigError } from 'ish-core/store/core/error'; +import { mapErrorToAction, mapToPayloadProperty, whenFalsy } from 'ish-core/utils/operators'; import { loadServerConfig, loadServerConfigFail, loadServerConfigSuccess } from './server-config.actions'; import { isServerConfigurationLoaded } from './server-config.selectors'; @@ -39,4 +40,12 @@ export class ServerConfigEffects { ) ) ); + + mapToServerConfigError$ = createEffect(() => + this.actions$.pipe( + ofType(loadServerConfigFail), + mapToPayloadProperty('error'), + map(error => serverConfigError({ error })) + ) + ); }