1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 16:23:44 +00:00

[PM-22992] Send lastKnownRevisionDate with Attachment API calls (#16862)

* Add lastKnownRevisionDate to Attachment methods.

* Address issues raised by Claude PR

* Fix string errors

* Show error to user in event of attachment upload failure

* Improve error handling for missing cipher

* Add unit tests for attachment lastKnownRevisionDate

* Remove generic title from toast errors

* Move lastKnwonRevisionDate to function input
This commit is contained in:
Nik Gilmore
2025-10-22 16:19:57 -07:00
committed by GitHub
parent 740fe0787f
commit 0ec3f661d5
8 changed files with 183 additions and 2 deletions

View File

@@ -240,6 +240,49 @@ describe("CipherAttachmentsComponent", () => {
message: "maxFileSize",
});
});
it("shows error toast with server message when saveAttachmentWithServer fails", async () => {
const file = { size: 100 } as File;
component.attachmentForm.controls.file.setValue(file);
const serverError = new Error("Cipher has been modified by another client");
saveAttachmentWithServer.mockRejectedValue(serverError);
await component.submit();
expect(showToast).toHaveBeenCalledWith({
variant: "error",
message: "Cipher has been modified by another client",
});
});
it("shows error toast with fallback message when error has no message property", async () => {
const file = { size: 100 } as File;
component.attachmentForm.controls.file.setValue(file);
saveAttachmentWithServer.mockRejectedValue({ code: "UNKNOWN_ERROR" });
await component.submit();
expect(showToast).toHaveBeenCalledWith({
variant: "error",
message: "unexpectedError",
});
});
it("shows error toast with string error message", async () => {
const file = { size: 100 } as File;
component.attachmentForm.controls.file.setValue(file);
saveAttachmentWithServer.mockRejectedValue("Network connection failed");
await component.submit();
expect(showToast).toHaveBeenCalledWith({
variant: "error",
message: "Network connection failed",
});
});
});
describe("success", () => {

View File

@@ -222,6 +222,19 @@ export class CipherAttachmentsComponent implements OnInit, AfterViewInit {
this.onUploadSuccess.emit();
} catch (e) {
this.logService.error(e);
// Extract error message from server response, fallback to generic message
let errorMessage = this.i18nService.t("unexpectedError");
if (typeof e === "string") {
errorMessage = e;
} else if (e?.message) {
errorMessage = e.message;
}
this.toastService.showToast({
variant: "error",
message: errorMessage,
});
}
};