Kong / unirest-ruby

Unirest in Ruby: Simplified, lightweight HTTP client library.
http://unirest.io/ruby
MIT License
364 stars 83 forks source link

How do I handle timeout? #23

Open haggen opened 9 years ago

haggen commented 9 years ago

I tried forcing a timeout and got a RuntimeError raised with the message "Request Timeout".

Is that it ? Do I have to test the message of a generic exception ? Shouldn't it raise something more particular like TimeoutError or anything like that ?

Thanks in advance.

krsyoung commented 8 years ago

@haggen I have a smilar problem in that I've been handling Errno::ETIMEDOUT but not RuntimeError (Request Timeout). Curious, what did you do to force the timeout?

haggen commented 8 years ago

@krsyoung I used a mocking gem called webmock https://github.com/bblimke/webmock

The code was something like this:

stub_request(:any, 'example.org').to_timeout
Unirest.get('example.org') #=> Got RuntimeError when I was expecting Timeout