diff --git a/libs/angular/src/auth/components/remove-password.component.spec.ts b/libs/angular/src/auth/components/remove-password.component.spec.ts index ddabd690306..5e9d823525a 100644 --- a/libs/angular/src/auth/components/remove-password.component.spec.ts +++ b/libs/angular/src/auth/components/remove-password.component.spec.ts @@ -4,6 +4,7 @@ import { mock } from "jest-mock-extended"; import { OrganizationApiServiceAbstraction } from "@bitwarden/common/admin-console/abstractions/organization/organization-api.service.abstraction"; import { Organization } from "@bitwarden/common/admin-console/models/domain/organization"; import { KeyConnectorService } from "@bitwarden/common/auth/abstractions/key-connector.service"; +import { ErrorResponse } from "@bitwarden/common/models/response/error.response"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; import { SyncService } from "@bitwarden/common/platform/sync"; @@ -128,9 +129,16 @@ describe("RemovePasswordComponent", () => { expect(mockRouter.navigate).toHaveBeenCalledWith([""]); }); - it("should handle errors and show error toast", async () => { + it("should handle response errors and show error toast", async () => { const errorMessage = "Can't migrate user error"; - mockKeyConnectorService.migrateUser.mockRejectedValue(new Error(errorMessage)); + mockKeyConnectorService.migrateUser.mockRejectedValue( + new ErrorResponse( + { + message: errorMessage, + }, + 404, + ), + ); mockI18nService.t.mockReturnValue("error occurred"); await component.convert(); @@ -170,10 +178,17 @@ describe("RemovePasswordComponent", () => { expect(mockRouter.navigate).toHaveBeenCalledWith([""]); }); - it("should handle errors and show error toast", async () => { + it("should handle response errors and show error toast", async () => { const errorMessage = "Can't leave organization error"; mockDialogService.openSimpleDialog.mockResolvedValue(true); - mockOrganizationApiService.leave.mockRejectedValue(new Error(errorMessage)); + mockOrganizationApiService.leave.mockRejectedValue( + new ErrorResponse( + { + message: errorMessage, + }, + 404, + ), + ); mockI18nService.t.mockReturnValue("error occurred"); await component.leave(); diff --git a/libs/angular/src/auth/components/remove-password.component.ts b/libs/angular/src/auth/components/remove-password.component.ts index 8fd4e7bba95..baf986d3211 100644 --- a/libs/angular/src/auth/components/remove-password.component.ts +++ b/libs/angular/src/auth/components/remove-password.component.ts @@ -6,6 +6,7 @@ import { OrganizationApiServiceAbstraction } from "@bitwarden/common/admin-conso import { Organization } from "@bitwarden/common/admin-console/models/domain/organization"; import { AccountService } from "@bitwarden/common/auth/abstractions/account.service"; import { KeyConnectorService } from "@bitwarden/common/auth/abstractions/key-connector.service"; +import { ErrorResponse } from "@bitwarden/common/models/response/error.response"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; import { UserId } from "@bitwarden/common/types/guid"; @@ -76,7 +77,7 @@ export class RemovePasswordComponent implements OnInit { } catch (e) { this.continuing = false; - if (e instanceof Error) { + if (e instanceof ErrorResponse) { this.toastService.showToast({ variant: "error", title: this.i18nService.t("errorOccurred"), @@ -111,7 +112,7 @@ export class RemovePasswordComponent implements OnInit { } catch (e) { this.leaving = false; - if (e instanceof Error) { + if (e instanceof ErrorResponse) { this.toastService.showToast({ variant: "error", title: this.i18nService.t("errorOccurred"),