diff --git a/apps/browser/src/background/main.background.ts b/apps/browser/src/background/main.background.ts index 6e2421e499..cfb44c6c36 100644 --- a/apps/browser/src/background/main.background.ts +++ b/apps/browser/src/background/main.background.ts @@ -1347,14 +1347,17 @@ export default class MainBackground { if (flagEnabled("sdk")) { // Warn if the SDK for some reason can't be initialized let supported = false; + let error: Error; try { supported = await firstValueFrom(this.sdkService.supported$); } catch (e) { - // Do nothing. + error = e; } if (!supported) { - this.sdkService.failedToInitialize().catch((e) => this.logService.error(e)); + this.sdkService + .failedToInitialize("background", error) + .catch((e) => this.logService.error(e)); } } diff --git a/apps/browser/src/popup/app.component.ts b/apps/browser/src/popup/app.component.ts index 3c8752f3a7..f3693e4f8a 100644 --- a/apps/browser/src/popup/app.component.ts +++ b/apps/browser/src/popup/app.component.ts @@ -1,7 +1,7 @@ import { ChangeDetectorRef, Component, NgZone, OnDestroy, OnInit, inject } from "@angular/core"; import { takeUntilDestroyed } from "@angular/core/rxjs-interop"; import { NavigationEnd, Router, RouterOutlet } from "@angular/router"; -import { Subject, takeUntil, firstValueFrom, concatMap, filter, tap, catchError, of } from "rxjs"; +import { Subject, takeUntil, firstValueFrom, concatMap, filter, tap } from "rxjs"; import { LogoutReason } from "@bitwarden/auth/common"; import { AccountService } from "@bitwarden/common/auth/abstractions/account.service"; @@ -71,21 +71,24 @@ export class AppComponent implements OnInit, OnDestroy { ) { if (flagEnabled("sdk")) { // Warn if the SDK for some reason can't be initialized - this.sdkService.supported$ - .pipe( - takeUntilDestroyed(), - catchError(() => { - return of(false); - }), - ) - .subscribe((supported) => { + this.sdkService.supported$.pipe(takeUntilDestroyed()).subscribe({ + next: (supported) => { if (!supported) { this.logService.debug("SDK is not supported"); - this.sdkService.failedToInitialize().catch((e) => this.logService.error(e)); + this.sdkService + .failedToInitialize("popup", undefined) + .catch((e) => this.logService.error(e)); } else { this.logService.debug("SDK is supported"); } - }); + }, + error: (e: unknown) => { + this.sdkService + .failedToInitialize("popup", e as Error) + .catch((e) => this.logService.error(e)); + this.logService.error(e); + }, + }); } } diff --git a/apps/cli/src/service-container/service-container.ts b/apps/cli/src/service-container/service-container.ts index 3424e3fb28..8d1ad6b2e7 100644 --- a/apps/cli/src/service-container/service-container.ts +++ b/apps/cli/src/service-container/service-container.ts @@ -872,7 +872,7 @@ export class ServiceContainer { } if (!supported) { - this.sdkService.failedToInitialize().catch((e) => this.logService.error(e)); + this.sdkService.failedToInitialize("cli").catch((e) => this.logService.error(e)); } } } diff --git a/apps/desktop/src/app/app.component.ts b/apps/desktop/src/app/app.component.ts index aba664e7a8..f1f5a15ac5 100644 --- a/apps/desktop/src/app/app.component.ts +++ b/apps/desktop/src/app/app.component.ts @@ -180,7 +180,7 @@ export class AppComponent implements OnInit, OnDestroy { .subscribe((supported) => { if (!supported) { this.logService.debug("SDK is not supported"); - this.sdkService.failedToInitialize().catch((e) => this.logService.error(e)); + this.sdkService.failedToInitialize("desktop").catch((e) => this.logService.error(e)); } else { this.logService.debug("SDK is supported"); } diff --git a/apps/web/src/app/app.component.ts b/apps/web/src/app/app.component.ts index f1b079b81a..704960c14c 100644 --- a/apps/web/src/app/app.component.ts +++ b/apps/web/src/app/app.component.ts @@ -104,7 +104,7 @@ export class AppComponent implements OnDestroy, OnInit { .subscribe((supported) => { if (!supported) { this.logService.debug("SDK is not supported"); - this.sdkService.failedToInitialize().catch((e) => this.logService.error(e)); + this.sdkService.failedToInitialize("web").catch((e) => this.logService.error(e)); } else { this.logService.debug("SDK is supported"); } diff --git a/libs/common/src/platform/abstractions/sdk/sdk.service.ts b/libs/common/src/platform/abstractions/sdk/sdk.service.ts index 04be8a992d..00c14bdfac 100644 --- a/libs/common/src/platform/abstractions/sdk/sdk.service.ts +++ b/libs/common/src/platform/abstractions/sdk/sdk.service.ts @@ -29,5 +29,5 @@ export abstract class SdkService { */ abstract userClient$(userId: UserId): Observable; - abstract failedToInitialize(): Promise; + abstract failedToInitialize(category: string, error?: Error): Promise; } diff --git a/libs/common/src/platform/services/sdk/default-sdk.service.ts b/libs/common/src/platform/services/sdk/default-sdk.service.ts index a161731544..b25ede006c 100644 --- a/libs/common/src/platform/services/sdk/default-sdk.service.ts +++ b/libs/common/src/platform/services/sdk/default-sdk.service.ts @@ -130,7 +130,7 @@ export class DefaultSdkService implements SdkService { return client$; } - async failedToInitialize(): Promise { + async failedToInitialize(category: string, error?: Error): Promise { // Only log on cloud instances if ( this.platformUtilsService.isDev() || @@ -139,9 +139,20 @@ export class DefaultSdkService implements SdkService { return; } - return this.apiService.send("POST", "/wasm-debug", null, false, false, null, (headers) => { - headers.append("SDK-Version", "1.0.0"); - }); + return this.apiService.send( + "POST", + "/wasm-debug", + { + category: category, + error: error?.message, + }, + false, + false, + null, + (headers) => { + headers.append("SDK-Version", "1.0.0"); + }, + ); } private async initializeClient(