mirror of
https://github.com/bitwarden/browser
synced 2025-12-11 22:03:36 +00:00
improved error display
This commit is contained in:
@@ -105,6 +105,10 @@ export class ImportChromeComponent implements OnInit, OnDestroy {
|
|||||||
// eslint-disable-next-line @angular-eslint/prefer-output-emitter-ref
|
// eslint-disable-next-line @angular-eslint/prefer-output-emitter-ref
|
||||||
@Output() csvDataLoaded = new EventEmitter<string>();
|
@Output() csvDataLoaded = new EventEmitter<string>();
|
||||||
|
|
||||||
|
// FIXME(https://bitwarden.atlassian.net/browse/CL-903): Migrate to Signals
|
||||||
|
// eslint-disable-next-line @angular-eslint/prefer-output-emitter-ref
|
||||||
|
@Output() error = new EventEmitter<string>();
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private formBuilder: FormBuilder,
|
private formBuilder: FormBuilder,
|
||||||
private controlContainer: ControlContainer,
|
private controlContainer: ControlContainer,
|
||||||
@@ -120,6 +124,10 @@ export class ImportChromeComponent implements OnInit, OnDestroy {
|
|||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logService.error("Error loading profiles from browser:", 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,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -177,9 +185,11 @@ export class ImportChromeComponent implements OnInit, OnDestroy {
|
|||||||
return null;
|
return null;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logService.error(`Chromium importer error: ${error}`);
|
this.logService.error(`Chromium importer error: ${error}`);
|
||||||
|
const keyOrMessage = this.getValidationErrorI18nKey(error);
|
||||||
return {
|
return {
|
||||||
errors: {
|
errors: {
|
||||||
message: this.i18nService.t(this.getValidationErrorI18nKey(error)),
|
message:
|
||||||
|
keyOrMessage === "errorOccurred" ? this.i18nService.t("errorOccurred") : keyOrMessage,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -188,10 +198,7 @@ export class ImportChromeComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
private getValidationErrorI18nKey(error: any): string {
|
private getValidationErrorI18nKey(error: any): string {
|
||||||
const message = typeof error === "string" ? error : error?.message;
|
const message = typeof error === "string" ? error : error?.message;
|
||||||
switch (message) {
|
return message || "errorOccurred";
|
||||||
default:
|
|
||||||
return "errorOccurred";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private getBrowserName(format: ImportType): string {
|
private getBrowserName(format: ImportType): string {
|
||||||
|
|||||||
@@ -463,6 +463,7 @@
|
|||||||
[onLoadProfilesFromBrowser]="this.onLoadProfilesFromBrowser"
|
[onLoadProfilesFromBrowser]="this.onLoadProfilesFromBrowser"
|
||||||
[format]="this.format"
|
[format]="this.format"
|
||||||
(csvDataLoaded)="this.formGroup.controls.fileContents.setValue($event)"
|
(csvDataLoaded)="this.formGroup.controls.fileContents.setValue($event)"
|
||||||
|
(error)="errorMessage = $event"
|
||||||
></import-chrome>
|
></import-chrome>
|
||||||
} @else {
|
} @else {
|
||||||
<bit-form-field>
|
<bit-form-field>
|
||||||
@@ -493,6 +494,9 @@
|
|||||||
></textarea>
|
></textarea>
|
||||||
</bit-form-field>
|
</bit-form-field>
|
||||||
}
|
}
|
||||||
|
<bit-callout type="danger" *ngIf="errorMessage" class="tw-mt-4">
|
||||||
|
{{ errorMessage }}
|
||||||
|
</bit-callout>
|
||||||
</bit-card>
|
</bit-card>
|
||||||
</bit-section>
|
</bit-section>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
@@ -112,6 +112,7 @@ import { ImportLastPassComponent } from "./lastpass";
|
|||||||
providers: ImporterProviders,
|
providers: ImporterProviders,
|
||||||
})
|
})
|
||||||
export class ImportComponent implements OnInit, OnDestroy, AfterViewInit {
|
export class ImportComponent implements OnInit, OnDestroy, AfterViewInit {
|
||||||
|
errorMessage: string | undefined = undefined;
|
||||||
DefaultCollectionType = CollectionTypes.DefaultUserCollection;
|
DefaultCollectionType = CollectionTypes.DefaultUserCollection;
|
||||||
|
|
||||||
featuredImportOptions: ImportOption[];
|
featuredImportOptions: ImportOption[];
|
||||||
@@ -439,6 +440,7 @@ export class ImportComponent implements OnInit, OnDestroy, AfterViewInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected async performImport() {
|
protected async performImport() {
|
||||||
|
this.errorMessage = undefined;
|
||||||
if (!(await this.validateImport())) {
|
if (!(await this.validateImport())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -454,22 +456,14 @@ export class ImportComponent implements OnInit, OnDestroy, AfterViewInit {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (importer === null) {
|
if (importer === null) {
|
||||||
this.toastService.showToast({
|
this.errorMessage = this.i18nService.t("selectFormat");
|
||||||
variant: "error",
|
|
||||||
title: this.i18nService.t("errorOccurred"),
|
|
||||||
message: this.i18nService.t("selectFormat"),
|
|
||||||
});
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const importContents = await this.setImportContents();
|
const importContents = await this.setImportContents();
|
||||||
|
|
||||||
if (importContents == null || importContents === "") {
|
if (importContents == null || importContents === "") {
|
||||||
this.toastService.showToast({
|
this.errorMessage = this.i18nService.t("selectFile");
|
||||||
variant: "error",
|
|
||||||
title: this.i18nService.t("errorOccurred"),
|
|
||||||
message: this.i18nService.t("selectFile"),
|
|
||||||
});
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -613,11 +607,7 @@ export class ImportComponent implements OnInit, OnDestroy, AfterViewInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.importBlockedByPolicy && this.organizationId == null) {
|
if (this.importBlockedByPolicy && this.organizationId == null) {
|
||||||
this.toastService.showToast({
|
this.errorMessage = this.i18nService.t("personalOwnershipPolicyInEffectImports");
|
||||||
variant: "error",
|
|
||||||
title: null,
|
|
||||||
message: this.i18nService.t("personalOwnershipPolicyInEffectImports"),
|
|
||||||
});
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user