blob: 5f6ebf34f1019df6fd8faeed6fd53a948f915838 [file]
/*
******************************************************************************
* Copyright © 2018 PTA GmbH.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
*
* http://www.eclipse.org/legal/epl-v10.html
*
******************************************************************************
*/
import { Injectable } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
import { ToasterMessage } from '../common/banner-message';
import { ErrorType } from '../common/enums';
import { ToasterMessageService, MessageDefines } from './toaster-message.service';
@Injectable()
export class HttpResponseInterceptorService {
constructor(
private messageService: ToasterMessageService,
private router: Router,
private activatedRoute: ActivatedRoute) { this.init(); }
private init(): void {
this.subscribeToMessageService();
}
private subscribeToMessageService() {
this.messageService.errorOccured$.subscribe((errorMessage: ToasterMessage) => {
if ((errorMessage.errorType === ErrorType.authentication)) {
if (this.router.url.includes('loggedout')) {
return;
}
const fwdUrl = this.activatedRoute.snapshot.queryParams['fwdUrl'];
if (fwdUrl) {
window.location.href = fwdUrl;
} else {
this.router.navigate(['/loggedout']);
}
this.messageService.loginLogoff$.emit(MessageDefines.MSG_LOG_OFF);
}
});
}
}