-
Notifications
You must be signed in to change notification settings - Fork 513
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
Body mixins throw TypeError: unusable
#1208
Comments
This is expected behavior. You cannot consume the body twice. |
@mcollina a bit quick on the trigger there. for the uninitiated, I would have enjoyed some more conversation about this before closing. @ronag what's the preferred method here in order to enable that? is there a reset? should we pipe into another stream? should we not rely on the JSON mixin and only use the text mixin? there are a lot of folks out there that are not intimately familiar with the spec and how things should work, additionally that's not documented at all in this repository. so that's leaving people in the dark, and some thorough discussion around that would absolutely help the community |
You are right, sorry about this. We should document it better.
I would call .text() and the call JSON.parse() on it. |
@mcollina thanks, much appreciated. I had a few extra minutes this morning after the daycare run and put together a small section in the README and accompanying PR. |
Bug Description
Calling
await body.text()
immediately followingawait body.json()
throwsTypeError: unusable
.I'm not entirely sure this is a bug. I tried to navigate the fetch spec on this, but maybe I'm just foggy today and didn't grok.
Reproducible By
When using
request
and making a successful request with200
response, I'm performing anawait body.json()
. If for some reason the resulting object is falsy or doesn't contain properties I expect, I'm attempting to callawait body.text()
so I can get an unfettered raw body to pump out to logs for later examination.Expected Behavior
I was expecting the body in plain text.
Logs & Screenshots
Here's the code I've been trying to run, of course missing additional context from the encompassing file (which I cannot share).
Environment
MacOS/AWS Linux
Node 14@latest
Additional context
The text was updated successfully, but these errors were encountered: