Skip to content

Commit

Permalink
fix: interceptor fixes to make new call if access_token is not presen…
Browse files Browse the repository at this point in the history
…t and not throw access_token errors to sentry (#3263)
  • Loading branch information
Aniruddha-Shriwant authored Nov 18, 2024
1 parent 57df4fb commit fbf0c91
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
3 changes: 1 addition & 2 deletions src/app/core/interceptors/httpInterceptor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,7 @@ describe('HttpConfigInterceptor', () => {
routerAuthService.fetchAccessToken.and.rejectWith(new Error('error'));

httpInterceptor.refreshAccessToken().subscribe({
error: (err) => {
expect(err).toBeTruthy();
complete: () => {
expect(userEventService.logout).toHaveBeenCalledTimes(1);
expect(secureStorageService.clearAll).toHaveBeenCalledTimes(1);
expect(storageService.clearAll).toHaveBeenCalledTimes(1);
Expand Down
10 changes: 5 additions & 5 deletions src/app/core/interceptors/httpInterceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from '@angular/common/http';
import { Injectable } from '@angular/core';

import { BehaviorSubject, Observable, forkJoin, from, iif, of, throwError } from 'rxjs';
import { BehaviorSubject, EMPTY, Observable, forkJoin, from, iif, of, throwError } from 'rxjs';
import { catchError, concatMap, filter, mergeMap, take } from 'rxjs/operators';

import { JwtHelperService } from '../services/jwt-helper.service';
Expand Down Expand Up @@ -67,12 +67,12 @@ export class HttpConfigInterceptor implements HttpInterceptor {
refreshAccessToken(): Observable<string> {
return from(this.tokenService.getRefreshToken()).pipe(
concatMap((refreshToken) => this.routerAuthService.fetchAccessToken(refreshToken)),
catchError((error) => {
catchError(() => {
this.userEventService.logout();
this.secureStorageService.clearAll();
this.storageService.clearAll();
globalCacheBusterNotifier.next();
return throwError(error);
return EMPTY;
}),
concatMap((authResponse) => this.routerAuthService.newAccessToken(authResponse.access_token)),
concatMap(() => from(this.tokenService.getAccessToken()))
Expand All @@ -88,7 +88,7 @@ export class HttpConfigInterceptor implements HttpInterceptor {
getAccessToken(): Observable<string> {
return from(this.tokenService.getAccessToken()).pipe(
concatMap((accessToken) => {
if (this.expiringSoon(accessToken)) {
if (!accessToken || this.expiringSoon(accessToken)) {
if (!this.accessTokenCallInProgress) {
this.accessTokenCallInProgress = true;
this.accessTokenSubject.next(null);
Expand Down Expand Up @@ -168,7 +168,7 @@ export class HttpConfigInterceptor implements HttpInterceptor {
this.secureStorageService.clearAll();
this.storageService.clearAll();
globalCacheBusterNotifier.next();
return throwError(error);
return EMPTY;
}
}
return throwError(error);
Expand Down

0 comments on commit fbf0c91

Please sign in to comment.