Skip to content
This repository has been archived by the owner on Aug 5, 2020. It is now read-only.

getHttpClient produces errors while removing and setting cookies #1039

Open
sethbattin opened this issue Jun 17, 2017 · 5 comments
Open

getHttpClient produces errors while removing and setting cookies #1039

sethbattin opened this issue Jun 17, 2017 · 5 comments

Comments

@sethbattin
Copy link
Contributor

The client.interceptors.response.use function in getHttpClient can produce errors for both setting and removing cookies if headers have already been sent. Specifically, these errors:

Error: Can't remove headers after they are sent line 86
Error: Can't set headers after they are sent. line 88

In my case, these errors occur when a gsBeforeRoute dispatches a GET after receiving a previous GET result. I will link below to my usage that generates the errors. With the current release of gluestick-shared, the errors are caught by redux promise middleware and cause silent failures with empty data. The errors can be caught closer to their source and ignored, which allows the data to be returned normally (PR incoming), but this ignores whatever is the root cause.

My use case is generating email content, which is solely server-side rendering and means I can't use the workaround in this comment:

Currently, the suggested solution for dealing with this problem is to make the API requests to A or B in the browser and not in gsBeforeRoute for apps where that is an issue.

Extra info: my gsBeforeRoute is sending three simultaneous requests to the same API endpoint. If I log the cookies that are triggering the errors, I can see that one of them is a session identifier. That suggests to me that the intent of "Ensure that any subsequent requests are passing the cookies" is not fulfilled.

Related: #881

@sethbattin
Copy link
Contributor Author

sethbattin commented Jun 17, 2017

@zamotany
Copy link
Contributor

I think I don't get it, I tried to reproduce it on a fresh project, with 3 request to mocked endpoint which sends cookies in gsBeforeRoutes and using Promise.all and 4th in onEnter in routes.js, but I don't get any error from getHttpClient and all those cookies are set correctly in browser.

Does the error is thrown, if one of those simultaneous requests fails?

@sethbattin
Copy link
Contributor Author

In my case the onEnter was first and gsBeforeRoute was second, but otherwise I'm not sure what the difference is. I think the number of requests doesn't matter, because I got the errors three times.

I put my patch in place locally and kept working on my task; I will try to recreate the issue now that I have the routes and data loading mostly complete..

@zamotany
Copy link
Contributor

Repository with reproduced error would be awesome, cause I want to eliminate the source of the problem, but cannot do without actual errors.

@sethbattin
Copy link
Contributor Author

The end result of my PR does not cause the error, even though it does similar steps: https://github.com/TrueCar/consumer-frontend/tree/c4a717ef8574f248edcffb1be065e8fd97722a7d So that's good; i was worried this would block deployment.

But the commit I referenced previously does still cause it. Unfortunately it's not easy to reproduce without some data for the Trade app; we make have to table this one until we check in some seed data.

# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants