fix(core-storage): Error Handling

Ref: #5472
This commit is contained in:
Nino
2025-11-12 14:00:18 +01:00
parent b827a6f0a0
commit 84af0acc2f

View File

@@ -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) => {