lib/nylas/http_client.rb in nylas-5.13.0 vs lib/nylas/http_client.rb in nylas-5.14.0

- old
+ new

@@ -187,12 +187,11 @@ end def parse_response(response) return response if response.is_a?(Enumerable) - json = StringIO.new(response) - Yajl::Parser.new(symbolize_names: true).parse(json) + Yajl::Parser.new(symbolize_names: true).parse(response) rescue Yajl::ParseError raise Nylas::JsonParseError end inform_on :parse_response, level: :debug, also_log: { result: true } @@ -220,12 +219,21 @@ def handle_anticipated_failure_mode(http_code:, response:) return if HTTP_SUCCESS_CODES.include?(http_code) exception = HTTP_CODE_TO_EXCEPTIONS.fetch(http_code, APIError) - raise exception.new(http_code, response) unless response.is_a?(Hash) + case response + when Hash + raise error_hash_to_exception(exception, response) + when RestClient::Response + raise exception.parse_error_response(response) + else + raise exception.new(http_code, response) + end + end - raise exception.new( + def error_hash_to_exception(exception, response) + exception.new( response[:type], response[:message], response.fetch(:server_error, nil) ) end