JsonApiClient / json_api_client

Build client libraries compliant with specification defined by jsonapi.org
MIT License
361 stars 186 forks source link

Fetching Next Page, Response Not JSON Results in: undefined method `fetch' for #<String:0x007f98e1600028> #256

Open sshaw opened 7 years ago

sshaw commented 7 years ago

Calling result.pages.next results in the following error when the response is not JSON:

/Users/skyes/.rvm/gems/ruby-2.3.0/gems/json_api_client-1.5.1/lib/json_api_client/parsers/parser.rb:61:in `handle_json_api': undefined method `fetch' for #<String:0x007f98e1600028> (NoMethodError)
    from /Users/skyes/.rvm/gems/ruby-2.3.0/gems/json_api_client-1.5.1/lib/json_api_client/parsers/parser.rb:11:in `block in parse'
    from /Users/skyes/.rvm/gems/ruby-2.3.0/gems/json_api_client-1.5.1/lib/json_api_client/parsers/parser.rb:8:in `tap'
    from /Users/skyes/.rvm/gems/ruby-2.3.0/gems/json_api_client-1.5.1/lib/json_api_client/parsers/parser.rb:8:in `parse'
    from /Users/skyes/.rvm/gems/ruby-2.3.0/gems/json_api_client-1.5.1/lib/json_api_client/query/requestor.rb:60:in `request'
    from /Users/skyes/.rvm/gems/ruby-2.3.0/gems/json_api_client-1.5.1/lib/json_api_client/query/requestor.rb:35:in `linked'
    from /Users/skyes/.rvm/gems/ruby-2.3.0/gems/json_api_client-1.5.1/lib/json_api_client/linking/top_level_links.rb:35:in `fetch_link'
    from /Users/skyes/.rvm/gems/ruby-2.3.0/gems/json_api_client-1.5.1/lib/json_api_client/paginating/paginator.rb:19:in `next'
    from json-api-client-test.rb:17:in `<main>'

Yes, sad that servers don't respect content types but nevertheless I would expect a different error from this instead of it treating the String has a Hash.

danbernier commented 6 years ago

I'm seeing this same error and stacktrace (mostly) in version 1.5.2, though afaict I'm not calling next:

undefined method `fetch' for #<String:0x0000000b7cc828>

/gems/json_api_client-1.5.2/lib/json_api_client/parsers/parser.rb:59 in handle_json_api
/gems/json_api_client-1.5.2/lib/json_api_client/parsers/parser.rb:11 in block in parse
/gems/json_api_client-1.5.2/lib/json_api_client/parsers/parser.rb:8 in tap
/gems/json_api_client-1.5.2/lib/json_api_client/parsers/parser.rb:8 in parse
/gems/json_api_client-1.5.2/lib/json_api_client/query/requestor.rb:60 in request
/gems/json_api_client-1.5.2/lib/json_api_client/query/requestor.rb:27 in get
/gems/json_api_client-1.5.2/lib/json_api_client/query/builder.rb:100 in find
/gems/json_api_client-1.5.2/lib/json_api_client/query/builder.rb:88 in to_a
/gems/json_api_client-1.5.2/lib/json_api_client/query/builder.rb:104 in method_missing
jufemaiz commented 6 years ago

Is your server expecting the page to be a parameter page["number"] rather than the default page["page"]? Ref: https://github.com/chingor13/json_api_client/blob/master/lib/json_api_client/paginating/paginator.rb#L7-L8

sshaw commented 6 years ago

Sorry, cannot remember.