import { DialogService } from '@hdca/fe-angular-dialog'; import { LocalizedRouterService } from '../services/localized-router/localized-router.service'; import { Component, OnInit, OnDestroy, Inject } from '@angular/core'; import * as fromApp from '../reducers'; import * as fromError from '../reducers/errors.reducer'; import { Store } from '@ngrx/store'; import { production } from '../tokens'; import { ManageSubscriptionsContainer } from '@hdca/fe-angular-shared'; import { Subscription} from 'rxjs'; @Component({ selector: 'error-container', templateUrl: './error.container.html' }) export class ErrorContainer extends ManageSubscriptionsContainer implements OnInit, OnDestroy { production: boolean; dialogFooter = [ { value: 'Go Back', classes: 'hdca-button--primary', onClick: () => { this.dialogService.close('api-dialog'); if (this.redirectURL) { this.router.go(this.redirectURL); } } } ]; requestURL = ''; redirectURL = ''; constructor( private store: Store, private router: LocalizedRouterService, private dialogService: DialogService, @Inject(production) productionDi) { super(); this.production = productionDi; } ngOnInit() { const storeSub: Subscription = this.store.select(fromApp.getAppError).subscribe((errorState: fromError.ErrorState) => { if (errorState.isError) { console.log('Error --> ', errorState.error, ' with request -->', errorState.requestURL, 'redirect URL -> ', errorState.redirectURL); if (!production) { this.requestURL = errorState.requestURL; this.redirectURL = errorState.redirectURL; this.dialogService.open('api-dialog'); } } }); this.subscriptions.push(storeSub); } ngOnDestroy() { super.ngOnDestroy(); } }