Skip to content

Commit

Permalink
feat: display server error page if the loading of the server configur…
Browse files Browse the repository at this point in the history
…ation fails
  • Loading branch information
SGrueber authored and shauke committed Sep 23, 2022
1 parent 27d937a commit 856b3f7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/app/core/store/core/error/error.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
3 changes: 2 additions & 1 deletion src/app/core/store/core/error/error.reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,6 +20,7 @@ export const errorReducer = createReducer(
serverError,
businessError,
communicationTimeoutError,
serverConfigError,
(state, action): ErrorState => ({
...state,
current: action.payload.error,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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$);
});
});
});
11 changes: 10 additions & 1 deletion src/app/core/store/core/server-config/server-config.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -39,4 +40,12 @@ export class ServerConfigEffects {
)
)
);

mapToServerConfigError$ = createEffect(() =>
this.actions$.pipe(
ofType(loadServerConfigFail),
mapToPayloadProperty('error'),
map(error => serverConfigError({ error }))
)
);
}

0 comments on commit 856b3f7

Please sign in to comment.