-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: interceptor fixes to make new call if access_token is not present and not throw access_token errors to sentry #3263
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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'; | ||||||||||||||||||||
|
@@ -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())) | ||||||||||||||||||||
|
@@ -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); | ||||||||||||||||||||
|
@@ -168,7 +168,7 @@ export class HttpConfigInterceptor implements HttpInterceptor { | |||||||||||||||||||
this.secureStorageService.clearAll(); | ||||||||||||||||||||
this.storageService.clearAll(); | ||||||||||||||||||||
globalCacheBusterNotifier.next(); | ||||||||||||||||||||
return throwError(error); | ||||||||||||||||||||
return EMPTY; | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Kabali style suggestion: Add telemetry before going silent! While returning EMPTY for 401s is stylish, we should track these occurrences for monitoring purposes. Here's how to do it with panache: + // Track authentication failures for monitoring
+ const errorContext = {
+ status: error.status,
+ blocked: error.headers.get('X-Mobile-App-Blocked'),
+ url: request.url
+ };
+ console.warn('Authentication failed - handling silently', errorContext);
return EMPTY; 📝 Committable suggestion
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nopes, access_token 401 is not something we should track There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Aniruddha-Shriwant, got it, boss! We'll skip tracking access_token 401 errors. Moving ahead! ✏️ Learnings added
|
||||||||||||||||||||
} | ||||||||||||||||||||
} | ||||||||||||||||||||
return throwError(error); | ||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick (assertive)
Listen up! Let's add some style to our error handling, machan!
The silent error handling with EMPTY is cool, but we might miss important token refresh failures. Let's add some logging before we go silent.
Here's how to do it with style:
catchError(() => { + console.warn('Token refresh failed - cleaning up and logging out silently'); this.userEventService.logout(); this.secureStorageService.clearAll(); this.storageService.clearAll(); globalCacheBusterNotifier.next(); return EMPTY; }),
📝 Committable suggestion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Aniruddha-Shriwant, no worries, boss! We'll leave it as it is.