SHARE
TWEET

Untitled

a guest Jun 18th, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top