mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-25 12:15:18 +01:00
[PM-7229] Fix circular dependency in ErrorHandler (#8573)
* call injector explicitly in ErrorHandler * Fallback to `super` on early error Co-authored-by: Matt Gibson <mgibson@bitwarden.com> --------- Co-authored-by: Matt Gibson <mgibson@bitwarden.com>,
This commit is contained in:
parent
22cca018f8
commit
a201e9cff1
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1075,7 +1075,7 @@ const safeProviders: SafeProvider[] = [
|
||||
safeProvider({
|
||||
provide: ErrorHandler,
|
||||
useClass: LoggingErrorHandler,
|
||||
deps: [LogService],
|
||||
deps: [],
|
||||
}),
|
||||
];
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user