Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: debugging #18

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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: 2 additions & 0 deletions utils/publishToGraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ export const publishToGraph = async (fileName, data) => {

const payload = new FormData();
payload.append("file", new Blob([data]), fileName);
console.log("Graph url:", url);

const response = await fetch(url, {
method: "POST",
body: payload,
});
console.log("response body:", await response.text(), response.body);
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix critical issue with response.text() consumption.

The current implementation has two critical issues:

  1. response.text() can only be consumed once. Calling it here will cause the parsing at line 27 to fail.
  2. Logging response.body (ReadableStream) is not useful.

Apply this fix to preserve the response body for parsing:

-  console.log("response body:", await response.text(), response.body);
+  const responseText = await response.text();
+  console.log(`[${new Date().toISOString()}] Graph IPFS response:`, responseText);
+
+  if (!response.ok) {
+    throw new Error(
+      `HTTP error! status: ${response.status}, Failed to pin to graph`
+    );
+  }
+
+  const result = parseNewlineSeparatedJSON(responseText);

Then update the subsequent code to use the stored responseText:

-  if (!response.ok) {
-    throw new Error(
-      `HTTP error! status: ${response.status}, Failed to pin to graph`
-    );
-  }
-
-  const result = parseNewlineSeparatedJSON(await response.text());
📝 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
console.log("response body:", await response.text(), response.body);
const responseText = await response.text();
console.log(`[${new Date().toISOString()}] Graph IPFS response:`, responseText);
if (!response.ok) {
throw new Error(
`HTTP error! status: ${response.status}, Failed to pin to graph`
);
}
const result = parseNewlineSeparatedJSON(responseText);


if (!response.ok) {
throw new Error(
Expand Down
Loading