Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sshaw opened this issue May 26, 2017 · 3 comments

Comments

@sshaw
Copy link

sshaw commented May 26, 2017

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
Copy link
Contributor

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
Copy link

jufemaiz commented Jan 18, 2018

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
Copy link
Author

sshaw commented Feb 21, 2018

Sorry, cannot remember.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants