Response.clone: Body has already been consumed
Unanswered
Upland Sandpiper posted this in #help-forum
Upland SandpiperOP
We're seeing the message "TypeError: Response.clone: Body has already been consumed." in lots of fetches, especially during site builds. This is requesting data from multiple backend services. It's not clear why all the responses are already consumed before they should read... Is anyone else seeing this?
4 Replies
You can only call res.json() on a response once.
.json (or .text, .arrayBuffer, .formData, etc) consumes the body. Once the body has been consumed it cannot be consumed again.
Same for request objects if you are using route handlers. req.json() can only be called once.
const res = await fetch(…)
await res.json() // works
await res.json() // doesn’t work
.json (or .text, .arrayBuffer, .formData, etc) consumes the body. Once the body has been consumed it cannot be consumed again.
Same for request objects if you are using route handlers. req.json() can only be called once.
Upland SandpiperOP
@joulev I get that. My problem is that someone is eating my responses, and I don't know who. i.e. our app has two very standardised functions that call
fetch
and then transform that to a typed response object. Neither of them have an execution path that would call .json()
twice. So it must be something "in the stack" - looking for hints on what that may be.Interesting, could you send an example?
fwiw, you can
-# assuming you clone before you consume body
res.clone().json()
tho :)-# assuming you clone before you consume body