fix: quirk with node 16 and response.clone()
#418
Closed
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.
🧰 Changes
We've found a quirk in how we're processing responses in Node 16 when making a successful API call where Node immediately kills the program without any errors or traces:
We've narrowed this down to the
response.clone()
call inparseResponse
where every time that line is called it pollutes the generalresponse
object that we have present and the program dies when we reachawait response.json()
.Infuriatingly, we have tests for this case of if we can't process a non-JSON response with
.json()
to instead call.text()
and this code, with the.clone()
call, work all just fine on Node 16 in the isolated test case:There's just something different about how it's run through the entire
api
flow that breaks it that we're unable to find so instead of trying to mess around with it I've slightly refactored theparseResponse
library to never call.clone()
instead, opting to runJSON.parse()
through a try-catch if we think that the content is JSON.It's not the best solution but hey it works.
🧬 QA & Testing
It's really hard to debug this because all the tests here have been, and still, pass, but if the code looks good to you then 👍