Skip to content

Commit

Permalink
Error Handling: Always check if the response is OK (i.e., response.st…
Browse files Browse the repository at this point in the history
…atus is 200) before trying to parse response.json(). Otherwise, it might throw an error.

Type Inference for variant: Specifying a type for variant could help clarify that it's optional and ensure type-safety.

Button Styling: Ensuring accessibility and consistent styling by applying appropriate roles and ARIA attributes, especially on interactive elements.
  • Loading branch information
jatin009v committed Oct 25, 2024
1 parent de1be6c commit 59095f5
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions components/apiKey/api-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function ApiKeyDialog({
className = "",
}: {
project_id: string;
variant?: any;
variant?: string;
className?: string;
}) {
const [busy, setBusy] = useState<boolean>(false);
Expand Down Expand Up @@ -52,6 +52,7 @@ export function ApiKeyDialog({
{apiKey}
</p>
<button
aria-label="Copy API Key"
className="bg-primary-foreground rounded-md"
onClick={() => {
navigator.clipboard.writeText(apiKey);
Expand All @@ -77,6 +78,9 @@ export function ApiKeyDialog({
},
}
);
if (!response.ok) {
throw new Error("Failed to generate API key");
}
const result = await response.json();
setApiKey(result.data.apiKey);
toast("Copy your API Key!", {
Expand All @@ -93,7 +97,7 @@ export function ApiKeyDialog({
}}
disabled={busy}
>
Generate API Key
{busy ? "Generating..." : "Generate API Key"}
</Button>
</DialogFooter>
</DialogContent>
Expand Down

0 comments on commit 59095f5

Please sign in to comment.