From 078939dbf9bebc3c7693a1f636e674862511fdb3 Mon Sep 17 00:00:00 2001 From: FlayInAHook Date: Thu, 3 Dec 2020 11:20:53 +0100 Subject: [PATCH] changed interceptor to handle 400 errors --- src/app/helper/token.interceptor.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/app/helper/token.interceptor.ts b/src/app/helper/token.interceptor.ts index 835a45a..0788af4 100644 --- a/src/app/helper/token.interceptor.ts +++ b/src/app/helper/token.interceptor.ts @@ -4,6 +4,7 @@ import { AuthService } from '../services/auth.service'; import { Observable, throwError, BehaviorSubject } from 'rxjs'; import { catchError, filter, take, switchMap } from 'rxjs/operators'; import { SnackBarService } from '../services/snackbar.service'; +import { Router, RouterStateSnapshot } from '@angular/router'; @Injectable() export class TokenInterceptor implements HttpInterceptor { @@ -11,7 +12,7 @@ export class TokenInterceptor implements HttpInterceptor { private isRefreshing = false; private requestTokenSubject: BehaviorSubject = new BehaviorSubject(null); - constructor(private authService: AuthService, private snackBar : SnackBarService) { } + constructor(private authService: AuthService, private snackBar : SnackBarService, private router: Router) { } intercept(request: HttpRequest, next: HttpHandler): Observable> { @@ -27,8 +28,11 @@ export class TokenInterceptor implements HttpInterceptor { errorMessage = `Error: ${error.error.message}`; } else { //server error - - if (error.status === 401) { + if (error.status === 400){ + this.authService.logout(); + errorMessage = "Die aktuelle Sitzung ist abgelaufen. Bitte loggen sie sich erneut ein." + this.router.navigate(["/login"], { queryParams: { returnUrl: this.router.routerState.snapshot.url } }); + } else if (error.status === 401) { var urlSplit : string[] = error.url.split("/"); if (urlSplit[3] === "users" && urlSplit[5] === "update"){ // Allow user pw updates to be processed correctly errorMessage = "Das aktuelle Passwort ist inkorrekt.";