fix: TypeError: Cannot read properties of undefined (reading 'body') … #1846
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 oroptions_
object is everundefined
. Without this guard, callingfetch()
on certain redirect sequences (e.g. 308 → 302 with a stream body) throwsChanges
src/index.js
, changed the redirect-step-9 guard to use optional chaining (request?.body
andoptions_?.body
) rather than assuming those objects always exist.dist/
bundle so the distributed code includes this guard.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