Skip to content
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

Can't read json from multiple interceptors #48

Closed
snortblt opened this issue Apr 15, 2016 · 5 comments
Closed

Can't read json from multiple interceptors #48

snortblt opened this issue Apr 15, 2016 · 5 comments
Labels

Comments

@snortblt
Copy link

snortblt commented Apr 15, 2016

If multiple interceptors are installed in the fetch client, only one of them can call response.json(). The second one to call causes an "already read" exception. I suppose that makes some sense from a stream reading perspective, but it doesn't make sense if multiple interceptors are allowed. Obviously, it would not be uncommon to want to read at least part of the response in both places.

Maybe a configureoption for caching the json in the client for mulitple access would be a solution?

@bryanrsmith
Copy link
Contributor

bryanrsmith commented Apr 15, 2016

Interceptors are chained such that the resolution value of one is propagated to the next. I think altering the data passed to a downstream interceptor would be unexpected. Would this be solved simply by cloning the response before reading its body?

@doktordirk
Copy link
Contributor

Or response.json(true) returns a clone

@EisenbergEffect
Copy link
Contributor

Any thoughts on how to resolve this?

@bryanrsmith
Copy link
Contributor

Response bodies can only be read once, so you just need to clone the response if you want to read it multiple times. response.clone().json()

@EisenbergEffect
Copy link
Contributor

Ok, so we'll just close this then :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants