title: Error Handling when Contacting 3rd Party APIs
body: <p>Given i have the following contrived code in a Rails controller: </p>
  
  <pre><code>class ProfilesController &lt; ApplicationController
    def show
      @profile = current_user.profile
      @content_from_third_party_api = @profile.get_that_third_party_content
    end
  end
  </code></pre>
  
  <p>This code in a <code>views/profiles/show.html.haml</code>: </p>
  
  <pre><code>%h1
    Profile Page!
  %h2
    Data from 3rd party:
  = @content_from_third_party_api.first.title
  </code></pre>
  
  <p>And this contrived code for <code>#get_that_third_party_content</code>:</p>
  
  <pre><code>def get_that_third_party_content
    uri = URI.parse("http://api.somesite.com/imfake/")
  
    http = Net::HTTP.new(uri.host, uri.port)
    request = Net::HTTP::Get.new(uri.request_uri)
    response = http.request(request)
  
    case response.code.to_i
    when 200 # the happy path
      response
    when (400..499)
      # What should I do/return here?  I have nothing useful to return to the caller.
    when (500..599)
      # Same goes for here...
    end
  end
  </code></pre>
  
  <p>How do I elegantly handle timeouts/errors/etc in <code>#get_that_third_party_content</code> given the following:</p>
  
  <ul>
  <li>The show view expects <code>@content_from_third_party_api</code> to NOT be nil.  If it's nil i'll get NilClass errors all over the place</li>
  <li>The show view needs to render Something</li>
  <li><code>#get_that_third_party_content</code> will return nothing if there's an error</li>
  <li>It feels like i need to be doing a lot of nil checking... and this seems really wrong</li>
  <li><code>rescue_from</code> seems like a good solution but I'm not sure if this is good</li>
  </ul>