Skip to content

Commit 9c2d624

Browse files
committed
improve-image-error-handling-and-error-page-buttons
1 parent f8b736d commit 9c2d624

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

app/error.tsx

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
} from "@/components/ui/card";
1010
import { track } from "@vercel/analytics";
1111
import Link from "next/link";
12+
import { useRouter } from "next/navigation";
1213

1314
export default function ErrorPage({
1415
error,
@@ -19,6 +20,7 @@ export default function ErrorPage({
1920
}) {
2021
console.error({ error });
2122
track("Error page");
23+
const router = useRouter();
2224

2325
return (
2426
<Card>
@@ -36,6 +38,9 @@ export default function ErrorPage({
3638
<Button className="w-full" onClick={() => reset()}>
3739
Try again
3840
</Button>
41+
<Button className="w-full" onClick={() => router.back()}>
42+
Go back
43+
</Button>
3944
<Link href="/support" className="w-full">
4045
<Button variant={"secondary"} className="w-full">
4146
Tell us what happened

app/image/[prompt]/page.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export default async function GenerateImagePage(params: {
4343
decodedPrompt,
4444
});
4545

46-
let generatedImageUrl: string;
46+
let generatedImageUrl: string | undefined;
4747

4848
if (isTestPrompt) {
4949
console.log(

lib/images/openai.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ export const generateOpenAiImageUrl = async ({
3232
style: "vivid",
3333
});
3434

35-
const url = response.data[0].url!;
35+
const url = response.data[0].url;
36+
if (!url) {
37+
console.error("No url");
38+
throw new Error("No url");
39+
}
3640
console.log("Generated image:", { url });
3741

3842
return url;

0 commit comments

Comments
 (0)