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()
.pipe(
catchError(_ => {
catchError(error => {
if (error.status === 403 || error.status === 401) {
localStorage.removeItem(ApiService.tokenKey);
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 => {
if (data)