blob: 73287e4f43616844f81d02227cbbaaf960c5bc7a [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, OnInit } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
import { MessageService, MessageDefines } from '../services/message.service';
import { BannerMessage } from '../common/banner-message';
import { SessionContext } from '../common/session-context';
import { ErrorType } from '../common/enums';
@Injectable()
export class HttpResponseInterceptorService {
constructor(
private messageService: MessageService,
private router: Router,
private sessionContext: SessionContext,
private activatedRoute: ActivatedRoute) { this.init(); }
private init(): void {
this.subscribeToMessageService();
}
private subscribeToMessageService() {
this.messageService.errorOccured$.subscribe((errorMessage: BannerMessage) => {
if ((errorMessage.errorType !== ErrorType.authentication)) {
const errorTypeIsLocked = errorMessage.errorType === ErrorType.locked;
errorMessage.showButton = errorTypeIsLocked;
if (errorTypeIsLocked) {
errorMessage.isSetTimeout = false;
}
this.sessionContext.setBannerMessage(errorMessage);
} else {
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);
}
});
}
}