Forked from ms-ati/httparty_issue_78_cant_see_bad_json_response.rb
Created
March 26, 2011 17:50
-
-
Save sandro/888478 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'httparty' | |
class FakeRestJsonApi | |
include HTTParty | |
base_uri 'http://google.com/THIS_IS_A_FAKE_URL' | |
headers 'Accept' => 'application/json' | |
default_params :output => 'json' | |
format :json | |
debug_output | |
class Parser < HTTParty::Parser | |
def json | |
begin | |
Crack::JSON.parse(body) | |
rescue StandardError | |
puts "Use another JSON parser" | |
end | |
end | |
end | |
parser Parser | |
def fake_get_request(params={}) | |
self.class.get('/fake_get_request', :body => params) | |
end | |
end | |
if __FILE__ == $0 | |
frj_api = FakeRestJsonApi.new | |
# | |
# NOTE: | |
# How can one retrieve the Response Body which causes the | |
# the Crack::ParseError in order to log and debug? | |
# | |
begin | |
resp = frj_api.fake_get_request | |
rescue Exception => e | |
require 'pp' | |
puts "\n--------------\nResponse from fake_get_request:\n\n" | |
pp resp | |
puts "\n--------------\n\n" | |
raise | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment