fix: add error handling to async clipboard handler in header.tsx
Wrap the async onClick handler for copying the SVG logo in a try-catch block to handle potential failures from fetch(), res.text(), and navigator.clipboard.writeText(). Show a success toast on copy and an error toast if any step fails. Fixes #722 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
26d523ebad
commit
29504c884b
|
|
@ -23,6 +23,7 @@ import {
|
|||
ContextMenuItem,
|
||||
ContextMenuTrigger,
|
||||
} from "./ui/context-menu";
|
||||
import { toast } from "sonner";
|
||||
|
||||
export function Header() {
|
||||
const [isMenuOpen, setIsMenuOpen] = useState(false);
|
||||
|
|
@ -66,9 +67,14 @@ export function Header() {
|
|||
<ContextMenuContent>
|
||||
<ContextMenuItem
|
||||
onClick={async () => {
|
||||
const res = await fetch(DEFAULT_LOGO_URL);
|
||||
const svg = await res.text();
|
||||
await navigator.clipboard.writeText(svg);
|
||||
try {
|
||||
const res = await fetch(DEFAULT_LOGO_URL);
|
||||
const svg = await res.text();
|
||||
await navigator.clipboard.writeText(svg);
|
||||
toast.success("SVG copied to clipboard");
|
||||
} catch {
|
||||
toast.error("Failed to copy SVG to clipboard");
|
||||
}
|
||||
}}
|
||||
>
|
||||
<HugeiconsIcon icon={Copy01Icon} />
|
||||
|
|
|
|||
Loading…
Reference in New Issue