From 48281c339d21c1451e89be5b8011bb7c7fb8afc8 Mon Sep 17 00:00:00 2001 From: Alex <3750118611@qq.com> Date: Tue, 23 Jun 2026 12:20:52 +0800 Subject: [PATCH 1/4] Handle upstream photo fetch failures in demo endpoints --- src/pages/_api/api/photo.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) 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 })); } From 1430458ac307858e69bde5d6569a1e41c9ed92c7 Mon Sep 17 00:00:00 2001 From: Alex <3750118611@qq.com> Date: Tue, 23 Jun 2026 12:21:50 +0800 Subject: [PATCH 2/4] Handle upstream photo fetch failures in demo endpoints --- src/pages/_api/api/sessions/photo.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) 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 })); } From 9f0fd8febaaf52408646cac26f453c204f0e3767 Mon Sep 17 00:00:00 2001 From: Alex <3750118611@qq.com> Date: Tue, 23 Jun 2026 12:23:01 +0800 Subject: [PATCH 3/4] Handle upstream photo fetch failures in demo endpoints --- src/pages/_api/api/payment-link/photo.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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 = ` From 6bd28731826991e9f5bfcb7cedb2978e14c23ba1 Mon Sep 17 00:00:00 2001 From: Alex <3750118611@qq.com> Date: Tue, 23 Jun 2026 12:23:44 +0800 Subject: [PATCH 4/4] Handle upstream photo fetch failures in demo endpoints --- src/pages/_api/api/payment-link/photo-stripe.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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 = `