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
Make sure we return on errored browser requests. #1349
Conversation
Your fix is correct but I really think this should be fixed in caseless like: this.dict = dict || {} on line 2 |
OK, so fix both places, or just caseless? I want to keep the test at least, but this will pass only when we update caseless in that case. |
IMO the fix should be applied only in caseless, then we keep the test in request of course. Ping @nylen as he's the one that have publish right for these modules. Once this got published in caseless this PR can be fixed and merged. My point about fixing this in caseless is that it's a bug in it in the first place. |
Agreed. PR sent in request/caseless#17 |
👍 awesome! I actually ran into this issue the other day and didn't know what to make of it.
I'd apply the fix here too (it's natural to say "do we have headers? if not, then don't do any of this stuff with headers"). But, as long as we fixed the issue and we have a test, that's the important part. |
btw @eiriksm I've added you as a contributor. thanks for your work on browserified request, it is very much appreciated! |
Added a commit with upgraded caseless to this PR. I don't really see the harm in having And thanks for adding me as a contributor. Wow, I am honored :) |
+1 from me, we fixed it twice. I'll merge this tomorrow if no one objects or beats me to it. |
What would happen here and here if It might be a very rare edge case but still you'll get |
d87975e
to
4d9e7da
Compare
I don't see how that would ever be possible. But be that as it may, you are of course right. The variable should not be uninitialized when it is being used later. I just pushed an updated branch with the if removed. Thanks for pointing that out, I should have checked for its usage before posting the suggestion. |
Looking good to me 👍 |
Make sure we return on errored browser requests.
Turns out that if browser requests are erroring out on an early stage (this could be error on DNS, cross-domain security cancellation or user has no internet connection), request will fail when trying the method
caseless.has
, because this will invoke Object.keys on undefined. So just wrapping the check here in a check for headers fixes the issue.I also added a browesr test for this. The test proves the problem: it will fail if request.js is not updated (for example with this code).
I realize I could have also sent a PR to caseless to avoid calling Object keys on an undefined object, but seems to me that we should not even invoke caseless when we have no headers to work with.
Please let me know if you feel this should be solved in another way
Have a great week!