rtrm HF Staff commited on
Commit
3ac3ba4
·
unverified ·
1 Parent(s): 2bc6604

fix: fetch debugging

Browse files
src/routes/api/fetch-url/+server.ts CHANGED
@@ -34,10 +34,12 @@ export async function GET({ url, fetch }) {
34
  const targetUrl = url.searchParams.get("url");
35
 
36
  if (!targetUrl) {
 
37
  throw error(400, "Missing 'url' parameter");
38
  }
39
 
40
  if (!isValidUrl(targetUrl)) {
 
41
  throw error(400, "Invalid or unsafe URL (only HTTPS is supported)");
42
  }
43
 
@@ -46,6 +48,7 @@ export async function GET({ url, fetch }) {
46
  const controller = new AbortController();
47
  const timeoutId = setTimeout(() => controller.abort(), FETCH_TIMEOUT);
48
 
 
49
  const response = await fetch(targetUrl, {
50
  signal: controller.signal,
51
  redirect: "error", // Block all redirects
@@ -55,6 +58,7 @@ export async function GET({ url, fetch }) {
55
  }).finally(() => clearTimeout(timeoutId));
56
 
57
  if (!response.ok) {
 
58
  throw error(response.status, `Failed to fetch: ${response.statusText}`);
59
  }
60
 
 
34
  const targetUrl = url.searchParams.get("url");
35
 
36
  if (!targetUrl) {
37
+ logger.warn("Missing 'url' parameter");
38
  throw error(400, "Missing 'url' parameter");
39
  }
40
 
41
  if (!isValidUrl(targetUrl)) {
42
+ logger.warn({ targetUrl }, "Invalid or unsafe URL (only HTTPS is supported)");
43
  throw error(400, "Invalid or unsafe URL (only HTTPS is supported)");
44
  }
45
 
 
48
  const controller = new AbortController();
49
  const timeoutId = setTimeout(() => controller.abort(), FETCH_TIMEOUT);
50
 
51
+ logger.debug("Fetching url: " + targetUrl);
52
  const response = await fetch(targetUrl, {
53
  signal: controller.signal,
54
  redirect: "error", // Block all redirects
 
58
  }).finally(() => clearTimeout(timeoutId));
59
 
60
  if (!response.ok) {
61
+ logger.error({ targetUrl }, `Error fetching URL`);
62
  throw error(response.status, `Failed to fetch: ${response.statusText}`);
63
  }
64