diff --git a/libs/angular/src/platform/services/logging-error-handler.ts b/libs/angular/src/platform/services/logging-error-handler.ts index 81cd537e7f..522412dd28 100644 --- a/libs/angular/src/platform/services/logging-error-handler.ts +++ b/libs/angular/src/platform/services/logging-error-handler.ts @@ -1,14 +1,22 @@ -import { ErrorHandler, Injectable } from "@angular/core"; +import { ErrorHandler, Injectable, Injector, inject } from "@angular/core"; import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; @Injectable() export class LoggingErrorHandler extends ErrorHandler { - constructor(private readonly logService: LogService) { - super(); - } + /** + * When injecting services into an `ErrorHandler`, we must use the `Injector` manually to avoid circular dependency errors. + * + * https://stackoverflow.com/a/57115053 + */ + private injector = inject(Injector); override handleError(error: any): void { - this.logService.error(error); + try { + const logService = this.injector.get(LogService, null); + logService.error(error); + } catch { + super.handleError(error); + } } } diff --git a/libs/angular/src/services/jslib-services.module.ts b/libs/angular/src/services/jslib-services.module.ts index 114c60c193..6378eed755 100644 --- a/libs/angular/src/services/jslib-services.module.ts +++ b/libs/angular/src/services/jslib-services.module.ts @@ -1075,7 +1075,7 @@ const safeProviders: SafeProvider[] = [ safeProvider({ provide: ErrorHandler, useClass: LoggingErrorHandler, - deps: [LogService], + deps: [], }), ];