Class: Geocodable::Request::JSONParser

Inherits:
Faraday::Response::Middleware
  • Object
show all
Defined in:
lib/geocodable/json_parser.rb

Instance Method Summary collapse

Instance Method Details

#on_complete(env) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/geocodable/json_parser.rb', line 4

def on_complete(env)
  begin
    env.body = JSON.parse(env.body, symbolize_names: true) if is_json?(env)
  rescue JSON::ParserError
    raise APIError.new(
      "Invalid response object from API: #{env.body}", env.status, env.body)
  end
end