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

JSON::ParserError #77

Open
fmasuhr opened this issue Jun 13, 2014 · 3 comments
Open

JSON::ParserError #77

fmasuhr opened this issue Jun 13, 2014 · 3 comments

Comments

@fmasuhr
Copy link

fmasuhr commented Jun 13, 2014

Sometimes the flickr api returns html with status 502 and in that case I get an JSON::ParserError

JSON::ParserError: 795: unexpected token at '<!DOCTYPE html> <html lang="en-us"><head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <meta charset="utf-8"> <title>Yahoo</title> <meta name="viewport" content="width=device-width,initial-scale=1,minimal-ui"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <style> html { height: 100%; } body { background: #fafafc url(https://s.yimg.com/nn/img/sad-panda-201402200631.png) 50% 50%; background-size: cover; height: 100%; text-align: center; font: 300 18px "helvetica neue", helvetica, verdana, tahoma, arial, sans-serif; } table { height: 100%; width: 100%; table-layout: fixed; border-collapse: collapse; ...nt-weight: 400; color: #400090; } p { color: #1A1A1A; } #message-1 { font-weight: bold; margin: 0; } #message-2 { display: inline-block; *display: inline; zoom: 1; max-width: 17em; _width: 17em; } </style> </head> <body> <!-- status code : 502 --> <!-- Server Connection Closed rw.api.flickr.com --> <!-- host machine: r24.ycpi.bf1.yahoo.net --> <table> <tbody><tr> <td> <img src="https://s.yimg.com/nn/img/yahoo-logo-201402200629.png" alt="Yahoo Logo"> <h1 style="margin-top:20px;">Will be right back...</h1> <p id="message-1">Thank you for your patience.</p> <p id="message-2">Our engineers are working quickly to resolve the issue.</p> </td> </tr> </tbody></table> </body></html> '

Here is the stack trace

/gems/json-1.8.1/lib/json/common.rb:155 in "parse"
/gems/json-1.8.1/lib/json/common.rb:155 in "parse"
/gems/json-1.8.1/lib/json/common.rb:334 in "load"
/gems/flickraw-0.9.8/lib/flickraw/api.rb:131 in "process_response"
/gems/flickraw-0.9.8/lib/flickraw/api.rb:59 in "call"

The problem is that it checks for XML only or else it will parse it as JSON

@hanklords
Copy link
Owner

This is an issue on flickr side... We could raise a dedicated exception on non 4XX http return code but I think it is not worth it.

@jzempel
Copy link

jzempel commented Aug 21, 2014

I get the same thing:

JSON::ParserError: 795: unexpected token at '<html> <head><title>502 Bad Gateway</title></head> <body bgcolor="white"> <center><h1>502 Bad Gateway</h1></center> <hr><center>nginx/1.4.4</center> </body> </html> '

It would be nice if flickraw handled the 502 and responded with the appropriate FlickRaw::FailedResponse.

@Joshfindit
Copy link

This is happening more and more as Flickr starts to topple.

Even if it was just something like:

begin
  parsedJSON = JSON.parse( request.data, quirks_mode: true )
  return parsedJSON
rescue JSON::ParserError => e
  return false
end

I think we'd all be fine with that

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

4 participants