lib/ably/rest/middleware/parse_json.rb in ably-0.1.4 vs lib/ably/rest/middleware/parse_json.rb in ably-0.1.5

- old
+ new

@@ -1,14 +1,19 @@ -require "json" +require 'faraday' +require 'json' module Ably module Rest module Middleware class ParseJson < Faraday::Response::Middleware + def on_complete(env) + env.body = parse(env.body) unless env.response_headers['Ably-Middleware-Parsed'] == true + end + def parse(body) JSON.parse(body) rescue JSON::ParserError => e - raise Ably::Exceptions::InvalidResponseBody, "Expected JSON response. #{e.message}" + raise Ably::Exceptions::InvalidResponseBody, "Expected JSON response: #{e.message}" end end end end end