feat: try refreshing if error not related to 401 or 403 error

This commit is contained in:
Polianin Nikita 2024-08-26 02:08:51 +03:00
parent 60d306f9c9
commit 8a584fd28a

View File

@ -33,10 +33,25 @@ export class TokenRefreshService {
this.authService.refreshToken() this.authService.refreshToken()
.pipe( .pipe(
catchError(_ => { catchError(error => {
localStorage.removeItem(ApiService.tokenKey); if (error.status === 403 || error.status === 401) {
this.refreshTokenExpireMs = -1; localStorage.removeItem(ApiService.tokenKey);
return of(undefined); this.refreshTokenExpireMs = -1;
return of(undefined);
}
let retryTime = this.refreshTokenExpireMs;
if (retryTime < environment.retryDelay)
retryTime = environment.retryDelay;
// 15 minutes
if (retryTime * 2 <= 900_000)
retryTime *= 2;
else
retryTime = 900_000;
return of(retryTime);
})) }))
.subscribe(data => { .subscribe(data => {
if (data) if (data)