@kawaiininja/fetch 1.0.50 → 1.0.52

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.
@@ -67,18 +67,25 @@ export const performFetch = async (url, method, token, body, headers, rest, debu
67
67
  catch (error) {
68
68
  // Distinguish Timeout vs User Abort
69
69
  const isTimeout = error.name === "AbortError" && !abortSignal?.aborted;
70
- lastError = isTimeout ? new Error("Network error") : error;
70
+ if (isTimeout) {
71
+ lastError = new Error(`Request timed out after ${timeoutDuration}ms`);
72
+ }
73
+ else {
74
+ lastError = error;
75
+ }
71
76
  // Stop if manually aborted by user
72
77
  if (abortSignal?.aborted)
73
78
  throw error;
79
+ // Stop if we shouldn't retry (e.g. 4xx errors usually don't throw here, but network errors do)
74
80
  if (attempt === maxAttempts)
75
81
  break;
82
+ const retryDelay = rest?.retryDelay || 1000;
76
83
  if (debug)
77
- console.warn(`[API] Attempt ${attempt} failed, retrying in 500ms...`);
78
- await new Promise((resolve) => setTimeout(resolve, 500));
84
+ console.warn(`[API] Attempt ${attempt} failed (${lastError.message}), retrying in ${retryDelay}ms...`);
85
+ await new Promise((resolve) => setTimeout(resolve, retryDelay));
79
86
  }
80
87
  }
81
- throw lastError || new Error("Network error");
88
+ throw lastError || new Error("Network connection failed");
82
89
  };
83
90
  export const parseResponse = async (res, parseAs) => {
84
91
  const type = res.headers.get("content-type") || "";
@@ -127,7 +127,7 @@ export const useFetch = (endpoint, baseOptions = {}) => {
127
127
  // 🛡️ STRICT MODE FIX: Do not abort requests on unmount.
128
128
  // In React 18 Strict Mode, the first mount starts the request, then unmounts immediately.
129
129
  // If we abort here, the shared promise (used by the second mount) dies, leaving the app in 'loading: true'.
130
- // abortRef.current.abort();
130
+ // abortRef.current.abort();..
131
131
  };
132
132
  }, []);
133
133
  const methods = createApiMethods({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kawaiininja/fetch",
3
- "version": "1.0.50",
3
+ "version": "1.0.52",
4
4
  "description": "Core fetch utility for Onyx Framework",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",