Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@yieldxyz/sdk",
"version": "0.0.6",
"version": "0.0.7",
"description": "Yield.xyz SDK",
"type": "module",
"scripts": {
Expand Down
3 changes: 2 additions & 1 deletion src/api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ export const customFetch = async <T>(
return response.json() as Promise<T>;
}

return Promise.reject(response);
const responseText = await response.text();
return Promise.reject(responseText);
Comment on lines +44 to +45
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# Check src/api-client.ts lines 44-45
echo "=== src/api-client.ts lines 44-45 ==="
sed -n '40,50p' src/api-client.ts

# Check orval.config.ts to verify customFetch setup
echo -e "\n=== orval.config.ts (mutator config) ==="
cat src/orval.config.ts 2>/dev/null || cat orval.config.ts 2>/dev/null || echo "Not found at expected location"

# Check src/index.ts error handling
echo -e "\n=== src/index.ts lines 18-28 ==="
sed -n '18,28p' src/index.ts

# Look for customFetch definition
echo -e "\n=== customFetch definition ==="
grep -r "customFetch" --include="*.ts" -B 2 -A 10 | head -50

Repository: stakekit/sdk

Length of output: 4473


🏁 Script executed:

# Get full customFetch function
echo "=== Full customFetch function ==="
sed -n '/^export const customFetch/,/^};$/p' src/api-client.ts

# Check a generated API function to see how it handles errors
echo -e "\n=== Sample generated API function ==="
grep -A 15 "export const getYields" src/api/index.ts | head -20

Repository: stakekit/sdk

Length of output: 1990


Don't reject a bare string from the public client.

When an API request fails, this code rejects the promise with a plain string instead of an Error object. SDK consumers will catch a string directly, breaking standard JavaScript error handling: instanceof Error checks fail, .stack and .message properties don't exist, and response metadata (status, headers) is lost unless embedded in the body text. Since customFetch is wired directly as the Orval mutator and src/index.ts includes no error wrapper layer, that raw string escapes to every caller unchanged.

Throw an Error object that preserves both the readable body text and response metadata:

Suggested fix
-  const responseText = await response.text();
-  return Promise.reject(responseText);
+  const responseText = await response.text();
+  throw Object.assign(
+    new Error(responseText || `HTTP ${response.status}`),
+    {
+      name: "ApiError",
+      status: response.status,
+      response,
+      body: responseText,
+    },
+  );
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const responseText = await response.text();
return Promise.reject(responseText);
const responseText = await response.text();
throw Object.assign(
new Error(responseText || `HTTP ${response.status}`),
{
name: "ApiError",
status: response.status,
response,
body: responseText,
},
);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/api-client.ts` around lines 44 - 45, The code currently rejects the
promise with a bare string (responseText); replace that with an Error instance
that includes the body text as the message and attach response metadata so
callers can inspect status/headers/body. In the function that reads responseText
(the customFetch/response handling code in src/api-client.ts), create const err
= new Error(responseText); then set (err as any).status = response.status; (err
as any).headers = Object.fromEntries(response.headers); (err as any).body =
responseText; and then throw err (or return Promise.reject(err)) instead of
Promise.reject(responseText).

};

const getUrl = ({
Expand Down