title: What’s the best way to handle exceptions from Net::HTTP?
body: <p>What’s the best way to rescue exceptions from Net::HTTP?</p>
  
  <p>Exceptions thrown are described in Ruby’s <code>socket.c</code>, like <code>Errno::ETIMEDOUT</code>, <code>Errno::ECONNRESET</code>, and <code>Errno::ECONNREFUSED</code>. The base class to all of these is <code>SystemCallError</code>, but it feels weird to write code like the following because <code>SystemCallError</code> seems so far removed from making an <code>HTTP</code> call:</p>
  
  <pre><code>begin
    response = Net::HTTP.get_response(uri)
    response.code == "200"
  rescue SystemCallError
    false
  end
  </code></pre>
  
  <p>Is it just me? Is there a better way to handle this beyond fixing <code>Net::HTTP</code> to handle the <code>Errno</code> exceptions that would likely pop up and encapsulate them in a parent <code>HttpRequestException</code>?</p>