1
0
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:
John Harrington
2025-12-05 16:28:18 -07:00
parent 9ff43a66c5
commit 386cf03c42
11 changed files with 164 additions and 21 deletions

View File

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

View File

@@ -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>

View File

@@ -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];