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

Handle 502 errors #10

Open
JustinAiken opened this issue Oct 16, 2014 · 0 comments
Open

Handle 502 errors #10

JustinAiken opened this issue Oct 16, 2014 · 0 comments

Comments

@JustinAiken
Copy link

The error:

I've noticed that occasionally the Readability API has a 502 error instead of a json response.:

<html>
  <head>
    <title>502 Bad Gateway</title>
  </head> 
  <body bgcolor="white">
    <center>
      <h1>502 Bad Gateway</h1>
    </center>
    <hr>
    <center>nginx/1.4.6 (Ubuntu)</center> 
  </body> 
</html>

The response.body is then an actual HTML body instead of a JSON string, so this code:

response = http.request(request)
Hashie::Mash.new MultiJson.decode(response.body)

passes an unparsable string to MultiJson.decode, resulting in this error:

MultiJson::ParseError: 795: unexpected token at
 '<html> <head><title>502 Bad Gateway</title></head>... '
/usr/local/rbenv/versions/2.1.1/lib/ruby/2.1.0/json/common.rb:155→ parse
/usr/local/rbenv/versions/2.1.1/lib/ruby/2.1.0/json/common.rb:155→ parse
multi_json-1.10.1/lib/multi_json/adapters/json_common.rb:16→ load
multi_json-1.10.1/lib/multi_json/adapter.rb:20→ load
multi_json-1.10.1/lib/multi_json.rb:119→ load
readit-0.1.0/lib/readit.rb:78→ https_request
readit-0.1.0/lib/readit.rb:53→ parse

Possible error catching:

  • Rescue MultiJson::ParseError
  • Check response status before passing to JSON parser

Possible error handling:

  • raise ReaditError
  • return empty hash
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

1 participant