guilhermesad / rspotify

A ruby wrapper for the Spotify Web API
MIT License
717 stars 290 forks source link

.track() method crashes when the limit exceed the maximum allowed #230

Open gordielachance opened 3 years ago

gordielachance commented 3 years ago

I get an error when trying to get tracks for an album using the method #tracks() :

RSpotify::Album.find('16NqPu4ZT94LJyEV6ukiyZ')

11: from /home/bozoun/.rvm/gems/ruby-2.7.0/gems/rspotify-2.10.1/lib/rspotify/album.rb:119:in `tracks'
    10: from /home/bozoun/.rvm/gems/ruby-2.7.0/gems/rspotify-2.10.1/lib/rspotify/connection.rb:39:in `block (2 levels) in singleton class'
     9: from /home/bozoun/.rvm/gems/ruby-2.7.0/gems/rspotify-2.10.1/lib/rspotify/connection.rb:66:in `send_request'
     8: from /home/bozoun/.rvm/gems/ruby-2.7.0/gems/rest-client-2.0.2/lib/restclient.rb:67:in `get'
     7: from /home/bozoun/.rvm/gems/ruby-2.7.0/gems/rest-client-2.0.2/lib/restclient/request.rb:52:in `execute'
     6: from /home/bozoun/.rvm/gems/ruby-2.7.0/gems/rest-client-2.0.2/lib/restclient/request.rb:145:in `execute'
     5: from /home/bozoun/.rvm/gems/ruby-2.7.0/gems/rest-client-2.0.2/lib/restclient/request.rb:715:in `transmit'
     4: from /home/bozoun/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/net/http.rb:933:in `start'
     3: from /home/bozoun/.rvm/gems/ruby-2.7.0/gems/rest-client-2.0.2/lib/restclient/request.rb:725:in `block in transmit'
     2: from /home/bozoun/.rvm/gems/ruby-2.7.0/gems/rest-client-2.0.2/lib/restclient/request.rb:809:in `process_result'
     1: from /home/bozoun/.rvm/gems/ruby-2.7.0/gems/rest-client-2.0.2/lib/restclient/abstract_response.rb:103:in `return!'
/home/bozoun/.rvm/gems/ruby-2.7.0/gems/rest-client-2.0.2/lib/restclient/abstract_response.rb:223:in `exception_with_response': 400 Bad Request (RestClient::BadRequest)
gordielachance commented 3 years ago

I found out. I was using

album.tracks(limit:100)

while albums only support 50 tracks as a limit. Maybe an error should be fired to handle this better.

Thanks for your amazing work !