Skip to content

Instantly share code, notes, and snippets.

@alexytiger
Created December 25, 2019 01:18
Show Gist options
  • Save alexytiger/4747e5e371cab31e30d6b4695f7df25d to your computer and use it in GitHub Desktop.
Save alexytiger/4747e5e371cab31e30d6b4695f7df25d to your computer and use it in GitHub Desktop.
e-book
import { Injectable } from '@angular/core';
import { Actions, ofType, createEffect } from '@ngrx/effects';
import { tap, map } from 'rxjs/operators';
import { ErrorActions, SnackBarActions } from '../actions';
import { AppearanceColor, SnackBarInterface } from '../../models';
@Injectable()
export class ErrorEffects {
constructor(private readonly actions$: Actions) {
}
handleError$ = createEffect(
() =>
this.actions$.pipe(
ofType(ErrorActions.errorMessage),
map(action => action.errorMsg),
tap(errorMsg => console.error('Got error:', errorMsg)),
map(errorMsg => {
const msg: SnackBarInterface = {
message: errorMsg,
color: AppearanceColor.Error
};
return SnackBarActions.open({payload: msg});
} )
)
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment