Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. export const showLoading = createAction(`[application] Show warning notification`);
  2. export const hideLoading = createAction(`[application] Show error notification`);
  3. export const showHttpResponseError = createAction(`[application] Show success notification`, props<{ error: HttpErrorResponse, nextAction: Action }>());
  4.  
  5. export type Actions = ReturnType<
  6. typeof showLoading |
  7. typeof hideLoading |
  8. typeof showHttpResponseError
  9. >;
  10.  
  11. @Injectable()
  12. export class ApplicationEffects
  13. {
  14. constructor(private actions$: Actions, private dialogsService: DialogsService, public notificationsService: NotificationService, private router: Router) { }
  15.  
  16. @Effect() public erroHandler$ = this.actions$
  17. .pipe(
  18. ofType(ApplicationActions.showHttpResponseError.type),
  19. switchMap(action => {
  20. const emptyAction = { type: 'noop' };
  21. const error = HttpErrorHandler.handle(action.error);
  22.  
  23. if (error.redirectTo != null) {
  24. this.router.navigate([error.redirectTo]);
  25. return of(emptyAction);
  26. }
  27.  
  28. if (action.error.status === 400) {
  29. this.notificationsService.notifyWarning('AVISO', error.messages);
  30. }
  31. else {
  32. this.dialogsService.errorDialog('ERRO', error.messages[0]);
  33. }
  34.  
  35. return action.nextAction ? of(action.nextAction) : of(emptyAction);
  36. },
  37. ));
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement