-
Notifications
You must be signed in to change notification settings - Fork 86
refactor: join options logic from http and fetchr client modules #348
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
Conversation
4f99a62
to
1e54dec
Compare
return response.text().then(function (responseBody) { | ||
return parseResponse(responseBody); | ||
return response.json().catch(function () { | ||
return null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return null?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup :( This is the fetchr behavior since a looong time ago. For me, we could throw an error in this case as well, but I'm not sure yet if we would be fixing or introducing a bug.
I need to add some functional tests to properly see how fetchr will behave with a 200 response and empty body. I think unless fetchr is not properly set in the server, there is no way to get a empty response...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall changes look good to me
This is the last big refactoring one. Here, I'm merging the code related to options normalization from the
http.client
andfetchr.cleint
modules. As you can see, when you put both together, we have a bunch of code (that I'll probably simplify in another PR).By centralizing the options we basically create only one interface that is passed down to all functions (it will be helpful when migrating to ts).
But more importantly,
httpRequest
does not compute the options unnecessarily on every retry. This makes the plate clean to fix the corner cases that I mentioned in the other PR:There will be also another PR improving the
FetchrError
class:Error
;options
object;name
,message
andreason
fields to make it easier for users to report/log errors;Since all this changes should be backward compatible, I would like to do it before migrating to ts/change the API.
I confirm that this contribution is made under the terms of the license found in the root directory of this repository's source tree and that I have the authority necessary to make this contribution on behalf of its copyright owner.