diff --git a/src/pages/_api/api/payment-link/photo-stripe.ts b/src/pages/_api/api/payment-link/photo-stripe.ts index 43e2383e..86f3a86c 100644 --- a/src/pages/_api/api/payment-link/photo-stripe.ts +++ b/src/pages/_api/api/payment-link/photo-stripe.ts @@ -10,8 +10,15 @@ export async function GET(request: Request) { if (result.status === 402) return result.challenge; - const res = await fetch("https://picsum.photos/1024/1024"); - const imageUrl = res.url; + let imageUrl: string; + try { + const res = await fetch("https://picsum.photos/1024/1024"); + if (!res.ok) throw new Error(`upstream responded ${res.status}`); + imageUrl = res.url; + } catch (error) { + console.error("[payment-link/photo-stripe] upstream fetch failed:", error); + return new Response("Failed to load photo from upstream", { status: 502 }); + } const html = ` diff --git a/src/pages/_api/api/payment-link/photo.ts b/src/pages/_api/api/payment-link/photo.ts index d528b059..6a9db130 100644 --- a/src/pages/_api/api/payment-link/photo.ts +++ b/src/pages/_api/api/payment-link/photo.ts @@ -8,8 +8,15 @@ export async function GET(request: Request) { if (result.status === 402) return result.challenge; - const res = await fetch("https://picsum.photos/1024/1024"); - const imageUrl = res.url; + let imageUrl: string; + try { + const res = await fetch("https://picsum.photos/1024/1024"); + if (!res.ok) throw new Error(`upstream responded ${res.status}`); + imageUrl = res.url; + } catch (error) { + console.error("[payment-link/photo] upstream fetch failed:", error); + return new Response("Failed to load photo from upstream", { status: 502 }); + } const html = ` diff --git a/src/pages/_api/api/photo.ts b/src/pages/_api/api/photo.ts index 553a73df..b0e6807a 100644 --- a/src/pages/_api/api/photo.ts +++ b/src/pages/_api/api/photo.ts @@ -8,8 +8,18 @@ export async function GET(request: Request) { if (result.status === 402) return result.challenge; - const res = await fetch("https://picsum.photos/1024/1024"); - const url = res.url; + let url: string; + try { + const res = await fetch("https://picsum.photos/1024/1024"); + if (!res.ok) throw new Error(`upstream responded ${res.status}`); + url = res.url; + } catch (error) { + console.error("[photo] upstream fetch failed:", error); + return Response.json( + { error: "Failed to load photo from upstream" }, + { status: 502 }, + ); + } return result.withReceipt(Response.json({ url })); } diff --git a/src/pages/_api/api/sessions/photo.ts b/src/pages/_api/api/sessions/photo.ts index 056bda80..c3547898 100644 --- a/src/pages/_api/api/sessions/photo.ts +++ b/src/pages/_api/api/sessions/photo.ts @@ -8,8 +8,18 @@ export async function GET(request: Request) { if (result.status === 402) return result.challenge; - const res = await fetch("https://picsum.photos/200/200"); - const url = res.url; + let url: string; + try { + const res = await fetch("https://picsum.photos/200/200"); + if (!res.ok) throw new Error(`upstream responded ${res.status}`); + url = res.url; + } catch (error) { + console.error("[sessions/photo] upstream fetch failed:", error); + return Response.json( + { error: "Failed to load photo from upstream" }, + { status: 502 }, + ); + } return result.withReceipt(Response.json({ url })); }