mirror of
https://dev.azure.com/hugendubel/ISA/_git/ISA-Frontend
synced 2025-12-28 22:42:11 +01:00
@@ -38,22 +38,52 @@ export class UserStorageProvider implements StorageProvider {
|
||||
filter((authenticated) => authenticated),
|
||||
switchMap(() =>
|
||||
this.#userStateService.UserStateGetUserState().pipe(
|
||||
catchError((error) => {
|
||||
if (error instanceof HttpErrorResponse && error.status === 404) {
|
||||
return [DEFAULT_USER_STATE_RESPONSE];
|
||||
}
|
||||
return throwError(() => error);
|
||||
}),
|
||||
retry({
|
||||
count: 3,
|
||||
delay: (error, retryCount) => {
|
||||
// Don't retry on 404 - it's expected for new users
|
||||
if (error instanceof HttpErrorResponse && error.status === 404) {
|
||||
this.#logger.debug(
|
||||
'User state not found (404) - using empty state',
|
||||
);
|
||||
throw error; // Stop retrying
|
||||
}
|
||||
|
||||
// For other errors (including 503), retry with exponential backoff
|
||||
this.#logger.warn('Retrying user state load', () => ({
|
||||
attempt: retryCount,
|
||||
error: error.message,
|
||||
status:
|
||||
error instanceof HttpErrorResponse ? error.status : 'unknown',
|
||||
}));
|
||||
return timer(1000 * retryCount); // Exponential backoff with timer
|
||||
return timer(1000 * retryCount); // Exponential backoff: 1s, 2s, 3s
|
||||
},
|
||||
}),
|
||||
catchError((error) => {
|
||||
// After all retries failed (or 404 encountered), return default state
|
||||
if (error instanceof HttpErrorResponse) {
|
||||
if (error.status === 404) {
|
||||
this.#logger.info(
|
||||
'User state not found - initializing with empty state',
|
||||
);
|
||||
} else {
|
||||
this.#logger.error(
|
||||
'Failed to load user state after retries - initializing with empty state',
|
||||
error,
|
||||
() => ({
|
||||
status: error.status,
|
||||
statusText: error.statusText,
|
||||
}),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
this.#logger.error(
|
||||
'Unexpected error loading user state - initializing with empty state',
|
||||
error as Error,
|
||||
);
|
||||
}
|
||||
return [DEFAULT_USER_STATE_RESPONSE];
|
||||
}),
|
||||
),
|
||||
),
|
||||
tap((res) => {
|
||||
|
||||
Reference in New Issue
Block a user