fix(ui): surface a visible error when secure share link creation fails

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
Mubashir Osmani 2026-07-10 21:46:55 +00:00
parent 7ba50e1e39
commit 864c826a57
2 changed files with 4 additions and 4 deletions

View file

@ -94,16 +94,15 @@ describe("CreatedKeyDisplay", () => {
expect(screen.getByRole("button", { name: /copy share link/i })).toBeInTheDocument();
});
it("should not display a share link when the share call fails", async () => {
it("should surface an error and show no link when the share call fails", async () => {
const user = userEvent.setup({ advanceTimers: vi.advanceTimersByTime });
vi.mocked(keyShareCreateCall).mockRejectedValue(new Error("boom"));
const consoleError = vi.spyOn(console, "error").mockImplementation(() => {});
render(<CreatedKeyDisplay apiKey="sk-test-123" accessToken="sk-admin" />);
await user.click(screen.getByRole("button", { name: /securely share/i }));
expect(keyShareCreateCall).toHaveBeenCalled();
expect(vi.mocked(MessageManager.error)).toHaveBeenCalledWith("Failed to create secure share link. boom");
expect(screen.queryByRole("button", { name: /copy share link/i })).not.toBeInTheDocument();
consoleError.mockRestore();
});
});

View file

@ -42,7 +42,8 @@ const CreatedKeyDisplay: React.FC<CreatedKeyDisplayProps> = ({ apiKey, accessTok
setShareLink(response.share_link);
MessageManager.success("Secure share link created");
} catch (error) {
console.error("Failed to create secure share link:", error);
const detail = error instanceof Error ? error.message : "Please try again.";
MessageManager.error(`Failed to create secure share link. ${detail}`);
} finally {
setSharing(false);
}