@sylphx/sdk 0.3.5 → 0.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2516,14 +2516,18 @@ function createWebhookHandler(config) {
2516
2516
  };
2517
2517
  }
2518
2518
  async function cachedFetch(params) {
2519
- const { url, headers, fallback, label, revalidate = 60 } = params;
2519
+ const { url, headers, fallback, label, revalidate = 60, timeout = 3e3 } = params;
2520
2520
  try {
2521
+ const controller = new AbortController();
2522
+ const timer = setTimeout(() => controller.abort(), timeout);
2521
2523
  const response = await fetch(url, {
2522
2524
  headers,
2525
+ signal: controller.signal,
2523
2526
  // @ts-expect-error - Next.js extended fetch option
2524
2527
  next: { revalidate }
2525
2528
  // Next.js Data Cache with TTL
2526
2529
  });
2530
+ clearTimeout(timer);
2527
2531
  if (!response.ok) {
2528
2532
  console.warn(`[Sylphx] Failed to fetch ${label}:`, response.status);
2529
2533
  return fallback;
@@ -2531,7 +2535,11 @@ async function cachedFetch(params) {
2531
2535
  const data = await response.json();
2532
2536
  return data ?? fallback;
2533
2537
  } catch (error) {
2534
- console.warn(`[Sylphx] Failed to fetch ${label}:`, error);
2538
+ if (error instanceof DOMException && error.name === "AbortError") {
2539
+ console.warn(`[Sylphx] Timeout fetching ${label} (${timeout}ms)`);
2540
+ } else {
2541
+ console.warn(`[Sylphx] Failed to fetch ${label}:`, error);
2542
+ }
2535
2543
  return fallback;
2536
2544
  }
2537
2545
  }