title: Error handling API calls via RestClient
body: <p>I'm using <a href="https://github.com/guilhermesad/rspotify/tree/master/lib/rspotify" rel="nofollow noreferrer">rspotify</a> to gather a list of data from albums names. All the while I've reached Spotify's api rate limit and would now like to create a few fallbacks to wait until the I can search and retry the search in order to not lose the (x) amount of data I've already retrieved.</p>
  
  <p>The gem uses RestClient but the unfortunately when I reach the rate limit I don't get the amount of time needed to wait until I can make another call:</p>
  
  <pre><code>.rvm/gems/ruby-2.5.1/gems/rest-client 2.0.2/lib/restclient/abstract_response.rb:223:in 'exception_with_response': 429 Too Many Requests (RestClient::TooManyRequests)
  </code></pre>
  
  <p>The above is all I'm given. The <code>begin/rescue</code> statement below doesn't work as when the code fails, it fails entirely without retrying. What am I doing wrong here?</p>
  
  <pre><code>begin
    search = RSpotify::Album.search(album[:title])
  rescue RestClient::ExceptionWithResponse, RestClient::TooManyRequests, Exception =&gt; e
    puts e
    retry
  rescue e
    puts e
    retry
  end
  </code></pre>
  
  <p>Here is how they suggest error handling:</p>
  
  <p><a href="https://github.com/rest-client/rest-client#response-callbacks-error-handling" rel="nofollow noreferrer">https://github.com/rest-client/rest-client#response-callbacks-error-handling</a></p>