HTTParty::Response inspect raises exception on parse failure #150

danbob opened this Issue Jun 21, 2012 · 3 comments


None yet
3 participants

danbob commented Jun 21, 2012

HTTParty was changed to use lazy parsing in this commit. As a result, some code that works normally will fail in the console.

For example, I have the following method:

def sanity(url)
rescue MultiJson::DecodeError

I called it in the console with a url that returned malformed JSON. The get call succeeded, but then the console called inspect on the HTTPResponse object that was returned, which called the parser and raised a MultiJson::DecodeError. Took me and my boss a while to figure out why the exception wasn't being caught by my method.


jnunemaker commented Jun 25, 2012

First, I hate that multi json stuff bubbles up. HTTParty should catch and re-raise an httparty specific error. Sorry about that. Second, not sure what to do about lazy verse not lazy. Lazy is really handy. I suppose if you really want to do a sanity check from the console calling inspect on the end in that method would do the trick.

Not sure there is anything httparty can do specifically about your problem. Closing the issue. Thanks for bringing it up though. If you have any suggestions as to what we could do to help with that, feel free to re-open with suggestions.

jnunemaker closed this Jun 25, 2012

danbob commented Jun 25, 2012

Once I understood what was going on it wasn't a problem, easy enough to work around. I agree that lazy parsing is nice; perhaps you could add a note about it in the docs? That should help anyone who runs into the same issue in the future, and it's a significant enough feature to deserve a mention anyway.

I'd like to point out that this one just bit us... we rescue a failed request and try to log the response we got back, but it turns out that response.inspect leads to... another exception! It would be nice if inspect on Response was able to rescue JSON failures.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment