Skip to content

Fix response body stream already read error in content submission - #117

Merged
github-actions[bot] merged 1 commit into
mainfrom
fix/response-body-stream-already-read-error
Oct 8, 2025
Merged

github-actions[bot] merged 1 commit into
mainfrom
fix/response-body-stream-already-read-error

Conversation

@ishaileshpant

Copy link
Copy Markdown
Collaborator

🔧 Fix Response Body Stream Error

Problem

After PR #116 was merged, a new error appeared: "Failed to execute 'text' on 'Response': body stream already read". This error occurs when trying to read the response body multiple times.

Root Cause

The error handling code was attempting to read the response body twice:

  1. First with response.json() (which failed for non-JSON responses)
  2. Then with response.text() (which failed because the stream was already consumed)

Solution

  • Clone the response before attempting JSON parsing
  • Add proper error handling for both JSON and text parsing failures
  • Prevent response body stream from being consumed multiple times

Technical Changes

// Before - caused "body stream already read" error
try {
    errorData = await response.json();
} catch (jsonError) {
    const textResponse = await response.text(); // ❌ Stream already consumed
}

// After - uses cloned response
const responseClone = response.clone();
try {
    errorData = await response.json();
} catch (jsonError) {
    const textResponse = await responseClone.text(); // ✅ Uses clone
}

Files Changed

  • github-auth.js - Fixed response body stream handling in createPullRequest method

Impact

  • 🎯 Resolves "Failed to execute 'text' on 'Response': body stream already read" error
  • 🚀 Improves error handling for both JSON and non-JSON responses
  • 🛡️ Prevents response body stream consumption issues
  • 🔍 Maintains proper error logging and debugging

Testing

  • Response body can now be read as both JSON and text when needed
  • No more "body stream already read" errors
  • Proper error handling for all response types
  • No linting errors

- Clone response before attempting to read as both JSON and text
- Add proper error handling for both JSON and text parsing failures
- Resolves 'Failed to execute text on Response: body stream already read' error
- Prevents response body stream from being consumed multiple times

The issue was that we were trying to read the response body twice:
1. First with response.json() (which failed)
2. Then with response.text() (which failed because stream was already consumed)

Solution: Clone the response before attempting JSON parsing, so we can
fall back to text parsing if JSON fails without consuming the original stream.
@vercel

vercel Bot commented Oct 8, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
prepguides-dev Ready Ready Preview Comment Oct 8, 2025 6:45pm

@ishaileshpant

Copy link
Copy Markdown
Collaborator Author

/approve

@github-actions
github-actions Bot merged commit 953ecf3 into main Oct 8, 2025
11 checks passed
@github-actions

github-actions Bot commented Oct 8, 2025

Copy link
Copy Markdown
Contributor

🚀 Admin-Approved and Auto-Merged!

This PR has been automatically merged to main after admin approval by @ishaileshpant.

✅ **Status**: Merged and deployed
🔗 **Commit**: `953ecf3bfd49d86f71f8501604c2f0d3d1128172`
📅 **Merged at**: 2025-10-08T18:45:51.223Z
👤 **Approved by**: Admin/Maintainer/Owner

Thank you for your contribution! 🎉

@ishaileshpant
ishaileshpant deleted the fix/response-body-stream-already-read-error branch October 13, 2025 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant