Skip to content

Commit

Permalink
build(error-handling): added error description to toast
Browse files Browse the repository at this point in the history
  • Loading branch information
NemesisLW committed Jul 12, 2024
1 parent 2bfb921 commit aacf088
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
6 changes: 5 additions & 1 deletion components/pickupline-generator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ function PickupLineGenerator() {
Pickup Line Generator
</h1>
{!state.pickupLines ? (
<PickupLineInputForm formAction={formAction} message={state.message} />
<PickupLineInputForm
formAction={formAction}
message={state.message}
error={state.errors}
/>
) : (
<OutputForm
pickupLines={state.pickupLines}
Expand Down
6 changes: 5 additions & 1 deletion components/pickupline-generator/input-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ import { Textarea } from "../ui/textarea";
function PickupLineInputForm({
formAction,
message,
error,
}: {
formAction: (payload: FormData) => void;
message?: string;
error?: string;
}) {
if (message === "error") {
toast.error("Failed to generate pickup lines. Please try again.");
toast.error("Failed to generate pickup lines. Please try again.", {
description: error,
});
}

return (
Expand Down
4 changes: 3 additions & 1 deletion lib/ai/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ export async function generateOutput(

try {
const timeoutPromise = setTimeout(7000).then(() => {
throw new Error("Request timed out");
throw new Error(
"Request timed out - Third party API Endpoints may be experiencing issues",
);
});
const generatePromise = generatePickupLines(validatedInputs.data);

Expand Down

0 comments on commit aacf088

Please sign in to comment.