diff --git a/client/src/app/core/interceptors/error.interceptor.ts b/client/src/app/core/interceptors/error.interceptor.ts index a7debf1..6187488 100644 --- a/client/src/app/core/interceptors/error.interceptor.ts +++ b/client/src/app/core/interceptors/error.interceptor.ts @@ -9,10 +9,11 @@ import { } from '@angular/common/http'; import { Observable, catchError, throwError } from 'rxjs'; import { Router } from '@angular/router'; +import { UserService } from '../services/user.service'; @Injectable({ providedIn: 'root' }) export class ErrorInterceptor implements HttpInterceptor { - constructor(private router: Router) {} + constructor(private router: Router, private userService: UserService) {} intercept( request: HttpRequest, @@ -21,10 +22,12 @@ export class ErrorInterceptor implements HttpInterceptor { return next.handle(request).pipe( catchError((error) => { if (error instanceof HttpErrorResponse) { + console.log('HTTP Response Error', error); if (error.status == HttpStatusCode.Unauthorized) { + this.userService.purgeAuth(); this.router.navigate(['/login'], { queryParams: { - redirectUrl: request.url, + redirectUrl: this.router.url, }, }); }