Closed ozzyaaron closed 3 years ago
@ozzyaaron thank you for opening up an issue. I'm curious here, what the value of response.return_code
is in this situation.
I'm a little reluctant to overload TimeoutError
because I'm not sure if there are valid reasons for a response body to be empty and this might be a source of confusion. I think EmptyBodyError
would be more descriptive, but I wonder if we can pry out of Typhoeus the underlying error itself.
Hi @bensheldon thanks for getting back!
I just checked and the response.return_code
.
For the first request I get :operation_timedout
then most times I get :couldnt_connect
but once I got :couldnt_resolve_host
.
I will say that from what I can see response.response_code
was always 0
which I think could be considered exceptional.
I totally get your reluctance to overload the error, I'm happy to update it to anything you wish!
Ideally I think I would like the error hierarchy to be:
# Error Hierarchy
#
# StandardError
# USPS::Error
# USPS::ConnectionError <= new error class
# USPS::TimeoutError
# USPS::AuthorizationError
And then in this case, raise a USPS::ConnectionError
if response.response_code == 0
.
@bensheldon I have updated the PR to reflect the changes you requested. I hope I got it right! :)
@ozzyaaron perfect! thank you! 🙌
Hi there, I hope I did everything requested. I tried to follow the directions in the Readme as best I could.
When testing on my development machine I noticed that if you disable your network connection then the first request will timeout. Subsequent requests however are not attempted and thus are not a timeout but do return a blank body.
I'm not sure whether the fault lies with Typhoes or libcurl itself as they're difficult to tease apart.
Either way, I thought that if we get a blank body I this should be considered an exceptional case and hence the PR.
@gaffneyc as commented in the code it is up to you whether you think this should be a different type of error. I figured for consumers of this gem, like us, this type of error might either fall into the
TimeoutError
case or anAddressNotFound
case. I pickedTimeoutError
as I thought it was more correct. I could also see you considering this a different type of error altogether 🤷