lib/soaspec/exchange_handlers/rest_handler.rb in soaspec-0.2.29 vs lib/soaspec/exchange_handlers/rest_handler.rb in soaspec-0.2.30

- old
+ new

@@ -1,5 +1,7 @@ +# frozen_string_literal: true + require_relative 'exchange_handler' require_relative 'rest_parameters' require_relative 'rest_parameters_defaults' require_relative 'rest_exchanger_factory' require_relative '../core_ext/hash' @@ -73,11 +75,11 @@ end # Override this with 'after_response' within class definition to perform an action # after response is retrieved # @param [RestClient::Response] _response Response to interpret to perform after block - def after_response(_response, _self) ; end + def after_response(_response, _self); end # Used in together with Exchange request that passes such override parameters # @param [Hash] override_parameters Params to characterize REST request # @option override_parameters [Hash] :params Extra parameters (E.g. headers) # @option override_parameters [String] suburl URL appended to base_url of class @@ -91,21 +93,24 @@ def make_request(override_parameters) @merged_options ||= init_merge_options # TODO: Is this var needed? Can method be passed to resource creation? test_values = interpret_parameters override_parameters # In order for ERB to be calculated at correct time, the first time request is made, the resource should be created @resource ||= RestClient::Resource.new(ERB.new(base_url_value).result(binding), @merged_options) - @resource_used = test_values[:suburl] ? @resource[test_values[:suburl]] : @resource + self.exception = nil # Remove any previously stored exception begin response = case test_values[:method] when :post, :patch, :put Soaspec::SpecLogger.info("request body: #{post_data(test_values)}") @resource_used.send(test_values[:method].to_s, post_data(test_values), test_values[:params]) else # :get, :delete @resource_used.send(test_values[:method].to_s, test_values[:params]) end - rescue RestClient::ExceptionWithResponse => e + rescue RestClient::Exception => e + self.exception = e + raise e unless e.respond_to? :response + response = e.response end Soaspec::SpecLogger.info("response: \n headers: #{response&.headers}\n body: #{response}\n") after_response(response, self) response