Sha256: a8adfff0c5cffd1e69bdaaa340dca6457e3c0e12f7b8ac83606d1e1f3fb48609
Contents?: true
Size: 731 Bytes
Versions: 73
Compression:
Stored size: 731 Bytes
Contents
require 'faraday' require 'json' module Ably module Rest module Middleware class ParseJson < Faraday::Response::Middleware def on_complete(env) if env.response_headers['Content-Type'] == 'application/json' env.body = parse(env.body) unless env.response_headers['Ably-Middleware-Parsed'] == true env.response_headers['Ably-Middleware-Parsed'] = true end end def parse(body) if body.length > 0 JSON.parse(body) else body end rescue JSON::ParserError => e raise Ably::Exceptions::InvalidResponseBody, "Expected JSON response: #{e.message}" end end end end end
Version data entries
73 entries across 73 versions & 2 rubygems