mirror of
https://github.com/bitwarden/browser
synced 2025-12-23 11:43:46 +00:00
rework error handling & presentation
This commit is contained in:
@@ -124,10 +124,8 @@ export class ImportChromeComponent implements OnInit, OnDestroy {
|
||||
);
|
||||
} catch (error) {
|
||||
this.logService.error("Error loading profiles from browser:", error);
|
||||
const keyOrMessage = this.getValidationErrorI18nKey(error);
|
||||
this.error.emit(
|
||||
keyOrMessage === "errorOccurred" ? this.i18nService.t("errorOccurred") : keyOrMessage,
|
||||
);
|
||||
const translatedMessage = this.translateValidationError(error);
|
||||
this.error.emit(translatedMessage);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -185,20 +183,40 @@ export class ImportChromeComponent implements OnInit, OnDestroy {
|
||||
return null;
|
||||
} catch (error) {
|
||||
this.logService.error(`Chromium importer error: ${error}`);
|
||||
const keyOrMessage = this.getValidationErrorI18nKey(error);
|
||||
const translatedMessage = this.translateValidationError(error);
|
||||
return {
|
||||
errors: {
|
||||
message:
|
||||
keyOrMessage === "errorOccurred" ? this.i18nService.t("errorOccurred") : keyOrMessage,
|
||||
message: translatedMessage,
|
||||
},
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private getValidationErrorI18nKey(error: any): string {
|
||||
private translateValidationError(error: any): string {
|
||||
const message = typeof error === "string" ? error : error?.message;
|
||||
return message || "errorOccurred";
|
||||
if (!message) {
|
||||
return this.i18nService.t("errorOccurred");
|
||||
}
|
||||
|
||||
// Check for specific browser not installed error
|
||||
const browserNotInstalledMatch = message.match(/chromiumImporterBrowserNotInstalled:([^:]+)/);
|
||||
if (browserNotInstalledMatch) {
|
||||
return this.i18nService.t("chromiumImporterBrowserNotInstalled", browserNotInstalledMatch[1]);
|
||||
}
|
||||
|
||||
// Generic IPC error
|
||||
if (message.includes("Error invoking remote method")) {
|
||||
return this.i18nService.t("errorOccurred");
|
||||
}
|
||||
|
||||
// Check if it's a known i18n key
|
||||
if (message === "browserAccessDenied") {
|
||||
return this.i18nService.t("browserAccessDenied");
|
||||
}
|
||||
|
||||
// Return raw message as fallback
|
||||
return message;
|
||||
}
|
||||
|
||||
private getBrowserName(format: ImportType): string {
|
||||
|
||||
@@ -463,6 +463,7 @@
|
||||
[onLoadProfilesFromBrowser]="this.onLoadProfilesFromBrowser"
|
||||
[format]="this.format"
|
||||
(csvDataLoaded)="this.formGroup.controls.fileContents.setValue($event)"
|
||||
(error)="this.handleChromeImportError($event)"
|
||||
></import-chrome>
|
||||
} @else {
|
||||
<bit-form-field>
|
||||
|
||||
@@ -513,6 +513,14 @@ export class ImportComponent implements OnInit, OnDestroy, AfterViewInit {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected handleChromeImportError(error: string) {
|
||||
this.toastService.showToast({
|
||||
variant: "error",
|
||||
title: this.i18nService.t("errorOccurred"),
|
||||
message: error,
|
||||
});
|
||||
}
|
||||
|
||||
protected setImportOptions() {
|
||||
this.featuredImportOptions = [...this.importService.featuredImportOptions];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user