mirror of
https://dev.azure.com/hugendubel/ISA/_git/ISA-Frontend
synced 2025-12-31 09:37:15 +01:00
Compare commits
1 Commits
0a1f25a1ee
...
fix/user-s
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
84af0acc2f |
@@ -38,22 +38,52 @@ export class UserStorageProvider implements StorageProvider {
|
|||||||
filter((authenticated) => authenticated),
|
filter((authenticated) => authenticated),
|
||||||
switchMap(() =>
|
switchMap(() =>
|
||||||
this.#userStateService.UserStateGetUserState().pipe(
|
this.#userStateService.UserStateGetUserState().pipe(
|
||||||
catchError((error) => {
|
|
||||||
if (error instanceof HttpErrorResponse && error.status === 404) {
|
|
||||||
return [DEFAULT_USER_STATE_RESPONSE];
|
|
||||||
}
|
|
||||||
return throwError(() => error);
|
|
||||||
}),
|
|
||||||
retry({
|
retry({
|
||||||
count: 3,
|
count: 3,
|
||||||
delay: (error, retryCount) => {
|
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', () => ({
|
this.#logger.warn('Retrying user state load', () => ({
|
||||||
attempt: retryCount,
|
attempt: retryCount,
|
||||||
error: error.message,
|
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) => {
|
tap((res) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user