mishig HF Staff commited on
Commit
8273830
·
verified ·
1 Parent(s): 5146f3d

Sync from GitHub via hub-sync

Browse files
Files changed (1) hide show
  1. src/app/api/proxy/[...path]/route.ts +27 -12
src/app/api/proxy/[...path]/route.ts CHANGED
@@ -86,12 +86,21 @@ export async function GET(
86
  if (v) headers.set(h, v);
87
  }
88
 
89
- const upstream = await fetch(upstreamUrl, {
90
- method: "GET",
91
- headers,
92
- redirect: "follow",
93
- cache: "no-store",
94
- });
 
 
 
 
 
 
 
 
 
95
 
96
  const respHeaders = new Headers();
97
  for (const h of FORWARD_RESPONSE_HEADERS) {
@@ -121,12 +130,18 @@ export async function HEAD(
121
  const token = req.cookies.get(COOKIE_NAME)?.value;
122
  if (token) headers.set("authorization", `Bearer ${token}`);
123
 
124
- const upstream = await fetch(upstreamUrl, {
125
- method: "HEAD",
126
- headers,
127
- redirect: "follow",
128
- cache: "no-store",
129
- });
 
 
 
 
 
 
130
 
131
  const respHeaders = new Headers();
132
  for (const h of FORWARD_RESPONSE_HEADERS) {
 
86
  if (v) headers.set(h, v);
87
  }
88
 
89
+ let upstream: Response;
90
+ try {
91
+ upstream = await fetch(upstreamUrl, {
92
+ method: "GET",
93
+ headers,
94
+ redirect: "follow",
95
+ cache: "no-store",
96
+ });
97
+ } catch (err) {
98
+ // Network error reaching huggingface.co (DNS, reset, etc.). The native
99
+ // <video> turns this into a generic load error with no details, so log
100
+ // server-side and return a useful 502 the client can surface in devtools.
101
+ console.error("[proxy] upstream fetch failed", err);
102
+ return new Response("Bad gateway: upstream fetch failed", { status: 502 });
103
+ }
104
 
105
  const respHeaders = new Headers();
106
  for (const h of FORWARD_RESPONSE_HEADERS) {
 
130
  const token = req.cookies.get(COOKIE_NAME)?.value;
131
  if (token) headers.set("authorization", `Bearer ${token}`);
132
 
133
+ let upstream: Response;
134
+ try {
135
+ upstream = await fetch(upstreamUrl, {
136
+ method: "HEAD",
137
+ headers,
138
+ redirect: "follow",
139
+ cache: "no-store",
140
+ });
141
+ } catch (err) {
142
+ console.error("[proxy] upstream HEAD failed", err);
143
+ return new Response(null, { status: 502 });
144
+ }
145
 
146
  const respHeaders = new Headers();
147
  for (const h of FORWARD_RESPONSE_HEADERS) {