Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export const showLoading = createAction(`[application] Show warning notification`);
- export const hideLoading = createAction(`[application] Show error notification`);
- export const showHttpResponseError = createAction(`[application] Show success notification`, props<{ error: HttpErrorResponse, nextAction: Action }>());
- export type Actions = ReturnType<
- typeof showLoading |
- typeof hideLoading |
- typeof showHttpResponseError
- >;
- @Injectable()
- export class ApplicationEffects
- {
- constructor(private actions$: Actions, private dialogsService: DialogsService, public notificationsService: NotificationService, private router: Router) { }
- @Effect() public erroHandler$ = this.actions$
- .pipe(
- ofType(ApplicationActions.showHttpResponseError.type),
- switchMap(action => {
- const emptyAction = { type: 'noop' };
- const error = HttpErrorHandler.handle(action.error);
- if (error.redirectTo != null) {
- this.router.navigate([error.redirectTo]);
- return of(emptyAction);
- }
- if (action.error.status === 400) {
- this.notificationsService.notifyWarning('AVISO', error.messages);
- }
- else {
- this.dialogsService.errorDialog('ERRO', error.messages[0]);
- }
- return action.nextAction ? of(action.nextAction) : of(emptyAction);
- },
- ));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement