fix bug rate_limit_details returned and a bug for intercom request header
Fix bug rate_limit_details returned as nil if net:http failed a request, and bug if intercom request header does not contain X-RateLimit-Reset header
Why?
Why are you making this change?
We have experienced a "bug" when using this library, we implemented our own sidekiq throttle limiter with existing rate_limit_details. It worked fine until at one point(my guess is) NET:HTTP request started failing and rate_limit_details was being returned as nil.
Another potential issue is if intercom does not return X-RateLimit-Reset header, the app will break because it will try to calculate try to subtract some time from Nil.
How?
Technical details on your change
For rate_limit_details:
- Not setting
request.rate_limit_detailsif its nil, because it should be empty hash in the initialiser. - Another solution is to pass
rate_limit_detailsto request object. It's kind of an anti-pattern that both classes are initialising the same variable and both of them are using it. We should initialise it in Client, pass it to Request, Request can modify it and send it back if needed.
For bug prone date arithmetic:
- Set current time if reset_at is not returned(if its NIL that is) so that the library does not throw used - on NIL object error.
- We should not call sleep if the sleep amount is 0.
Hey @Goran1708
Wondering if this pr is still in progress or if you'd like us to give it a review
Hey @Goran1708
Wondering if this pr is still in progress or if you'd like us to give it a review
Heya! Yeah sure, you can give it a review. Sorry I missed your notification.