Skip to content

fix: TypeError: Cannot read properties of undefined (reading 'body') … #1846

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Pruthvik-P
Copy link

fix: guard against undefined request/options in redirect step (fixes #1845)

Purpose

Prevent a runtime crash in the redirect-follow logic when either the internal request instance or options_ object is ever undefined. Without this guard, calling fetch() on certain redirect sequences (e.g. 308 → 302 with a stream body) throws

Changes

  • In src/index.js, changed the redirect-step-9 guard to use optional chaining (request?.body and options_?.body) rather than assuming those objects always exist.
  • Rebuilt the dist/ bundle so the distributed code includes this guard.
  • Manually verified with an Express-based repro (308 → 302 → 200) that:
    • Before patch: crash on second redirect
    • After patch: follows redirects correctly and logs “Done”

Additional information

I did not add unit tests in this PR—but I can follow up with a mocha/jest test if you'd like. Manual repro code is in test/manual/redirect-repro.js (feel free to move it or convert it into an automated test suite).


Checklist

  • I updated documentation if necessary
  • I added a unit test (or will follow up in a separate PR)

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.

TypeError: Cannot read properties of undefined (reading 'body')
1 participant