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
The error:
I've noticed that occasionally the Readability API has a 502 error instead of a json response.:
The
response.bodyis then an actual HTML body instead of a JSON string, so this code:passes an unparsable string to
MultiJson.decode, resulting in this error:Possible error catching:
MultiJson::ParseErrorPossible error handling:
ReaditError