lostisland/sawyer — pull request #30 by pseudomuto (2014-08-10 14:06:33+00:00)
Title: Strip response bodies before attempting to decode them

@pengwynn and @ technoweenie for review

# The Problem

When returning responses with no body, like 404s etc. a blank space is sometimes returned. When this happens a `JSON::ParserError` is raised quoting `unexpected token at ''`

In one particular case, using `head(:not_found)` in a rails app added this _blank_ response body which is how I came across this issue.

# Solution

Strip the response body if it's not `nil` before attempting to decode it with a serializer. I've done this in the call from `Agent#decode_body`, though this could be done in `Serializer#decode` if preferred.