lib/nylas/http_client.rb in nylas-4.6.2 vs lib/nylas/http_client.rb in nylas-4.6.3

- old
+ new

@@ -1,8 +1,10 @@ # frozen_string_literal: true module Nylas + require "yajl" + # Plain HTTP client that can be used to interact with the Nylas API sans any type casting. class HttpClient # rubocop:disable Metrics/ClassLength HTTP_CODE_TO_EXCEPTIONS = { 400 => InvalidRequest, 402 => MessageRejected, @@ -128,12 +130,13 @@ "Content-types" => "application/json" } end def parse_response(response) - response.is_a?(Enumerable) ? response : JSON.parse(response, symbolize_names: true) - rescue JSON::ParserError - response + return response if response.is_a?(Enumerable) + + json = StringIO.new(response) + Yajl::Parser.new(symbolize_names: true).parse(json) end inform_on :parse_response, level: :debug, also_log: { result: true } def url_for_path(path) protocol, domain = api_server.split("//")