stevenheidel / encore-backend

NO LONGER USED - Encore iPhone app API server written in Rails
https://www.crunchbase.com/organization/encore-fm#/entity
1 stars 0 forks source link

Bugs in artist endpoint #59

Closed slavik112211 closed 10 years ago

slavik112211 commented 10 years ago

Nick:

Also please let Slavik look at the logs for the artist endpoint he built two weeks ago. There seem to be many errors on the frontend when calling it.

After searching through production.log for errors, I've found the following:

  1. ActionController::RoutingError (No route matches [GET] "/api/v1/artists/What%20Cheer")
  2. ActionController::RoutingError (No route matches [GET] "/api/v1/artists/Jenny%20O./picture.json")
  3. F, [2013-09-30T07:07:40.233714 #25469] FATAL -- : TypeError (no implicit conversion of String into Integer): app/models/lastfm/event.rb:58:in []' app/models/lastfm/event.rb:58:inextract_tickets_url' app/models/lastfm/event.rb:4:in initialize' app/models/geo.rb:42:innew' app/models/geo.rb:42:in block in todays_events' app/models/geo.rb:41:ineach' app/models/geo.rb:41:in map' app/models/geo.rb:41:intodays_events' app/controllers/api/v1/events_controller.rb:84:in `today'

I'll proceed with fixing these, if there is anything else failing, let me know.

slavik112211 commented 10 years ago

Encore backend routes related to artists:

GET /api/v1/artists/:artist_id/events/past(.:format) api/v1/events#past GET /api/v1/artists/:artist_id/events/future(.:format) api/v1/events#future GET /api/v1/artists/search(.:format) api/v1/artists#search GET /api/v1/artists/combined_search(.:format) api/v1/artists#combined_search GET /api/v1/artists/:id/picture(.:format) api/v1/artists#picture GET /api/v1/artists/:id/info(.:format) api/v1/artists#info

  1. ActionController::RoutingError (No route matches [GET] "/api/v1/artists/What%20Cheer") Such route doesn't have an endpoint, and server-side fails if such route is requested. Not a bug on server-side.
slavik112211 commented 10 years ago

ActionController::RoutingError (No route matches [GET] "/api/v1/artists/Jenny%20O./picture.json")

Using dot (.) is not allowed in the artist name so far.

I, [2013-09-26T22:08:25.586448 #21628] INFO -- : Started GET "/api/v1/artists/Why?/picture.json" for 166.78.44.7 ActionController::RoutingError (No route matches [GET] "/api/v1/artists/Why"):

Using question mark (?) is not allowed in the artist name so far.

Started GET "/api/v1/artists/What%20Cheer?%20Brigade/picture.json" for 166.78.44.7 at 2013-09-28 00:04:16 +0000 F, [2013-09-28T00:04:16.977209 #22610] FATAL -- : ActionController::RoutingError (No route matches [GET] "/api/v1/artists/What%20Cheer"):

Using question mark (?) is not allowed in the artist name so far.

Started GET "/api/v1/artists/Mary%20J.%20Blige/picture.json" for 166.78.44.7 at 2013-09-28 18:20:26 +0000 F, [2013-09-28T18:20:26.267218 #22616] FATAL -- : ActionController::RoutingError (No route matches [GET] "/api/v1/artists/Mary%20J.%20Blige/picture.json")

Using dot (.) is not allowed in the artist name so far.

slavik112211 commented 10 years ago

Found the error that happens on the Artist#info endpoint:

I, [2013-09-26T22:03:27.558213 #21634] INFO -- : Processing by Api::V1::ArtistsController#info as JSON I, [2013-09-26T22:03:27.558296 #21634] INFO -- : Parameters: {"limit_events"=>"10", "id"=>"Avicii"} I, [2013-09-26T22:03:28.862642 #21634] INFO -- : Rendered api/v1/events/_events.json.jbuilder (2.5ms) I, [2013-09-26T22:03:28.862979 #21634] INFO -- : Rendered api/v1/artists/info.json.jbuilder (4.0ms) I, [2013-09-26T22:03:28.863397 #21634] INFO -- : Completed 500 Internal Server Error in 1305ms F, [2013-09-26T22:03:28.869177 #21634] FATAL -- : ActionView::Template::Error (undefined method `map' for #Event:0x007f15b6478a88): 1: json.array! events do |event| 2: json.partial! 'api/v1/events/event', event: event 3: end

The issue is fixed.

slavik112211 commented 10 years ago

F, [2013-09-30T07:07:40.233714 #25469] FATAL -- : TypeError (no implicit conversion of String into Integer): app/models/lastfm/event.rb:58:in []'

This happens in an edge case, whenever the Event returned from last.fm is not of form like: {"id"=>"2075035", "title"=>"First Gig", "artists"=> {"artist"=>"The Rolling Stones", "headliner"=>"The Rolling Stones"}, "venue"=> {"id"=>"8788342" }}

but something like the following: [1,2,3]

Fixed. (but not pushed to prod yet)

Problem with Last.fm is more broad, than just a problem in code written by myself ( F, [2013-09-30T07:07:40.233714 #25469] FATAL -- : TypeError (no implicit conversion of String into Integer): app/models/lastfm/event.rb:58:in []' )

This error repeats itself here:

I, [2013-09-29T17:13:16.556992 #7342] INFO -- : Processing by Api::V1::ArtistsController#combined_search as JSON I, [2013-09-29T17:13:16.557083 #7342] INFO -- : Parameters: {"latitude"=>"41.88322", "longitude"=>"-87.63243", "radius"=>"0.5", "tense"=>"past", "term"=>"ROLLING STONEA"} I, [2013-09-29T17:13:16.881220 #7342] INFO -- : Completed 500 Internal Server Error in 324ms F, [2013-09-29T17:13:16.884326 #7342] FATAL -- : TypeError (no implicit conversion of String into Integer): app/models/lastfm/base.rb:18:in []' app/models/lastfm/base.rb:18:inname' app/models/lastfm/artist.rb:8:in lastfm_id' app/controllers/api/v1/artists_controller.rb:8:incombined_search'

The reason this is happening is as follows:

Whenever the artist search is performed, Lastfm::Artist.new objects are created.

8:   def self.search(term) 
9:     LastfmAPI.artist_search(term).map { |a| Lastfm::Artist.new(a) }

10: end

The problem lies in the way artist_search() is implemented: def self.artist_search(term) get('artist.search', artist: term)["results"]["artistmatches"]["artist"] end

Map() method call expects an array of Artists, and not a Hash of attributes of a single Artist. It later fails in other Lastfm::Base methods, as the json provided is limited.

The problem wasn't introduced by my changes, rather by Last.fm returning a single Hash response, instead of Array[Hash, Hash].