lib/zephyr.rb in zephyr-1.0.2 vs lib/zephyr.rb in zephyr-1.0.3

- old
+ new

@@ -261,14 +261,18 @@ data = data.read if data.respond_to?(:read) params[:body] = data end # request has class methods for :delete, :get, :head, :put, and :post - response = Typhoeus::Request.send(method, uri(path_components).to_s, params) + http_start = Time.now.to_f + response = Typhoeus::Request.send(method, uri(path_components).to_s, params) + http_end = Time.now.to_f if defined?(Rails) - Rails.logger.info "lib/http.rb: #{method.to_s.upcase} #{uri(path_components).to_s}" + Rails.logger.info "[zephyr]: \"%s %s\" %s %0.4f" % [ + method.to_s.upcase, uri(path_components).to_s, response.code, (http_end - http_start) + ] end # be consistent with what came before response_headers = Headers.new.tap do |h| response.headers.split(/\n/).each do |header_line| @@ -281,11 +285,15 @@ if return_body?(method, response.code) result[:body] = response.body end result else - response_body = response.timed_out? || response.code == 0 ? "Exceeded #{timeout}ms" : response.body - raise FailedRequest.new(method, expect, response.code, response_headers.to_hash, response_body, response.timed_out?) + response_body = response.timed_out? || response.code == 0 ? "Exceeded #{timeout}ms" : response.body + failed_request = FailedRequest.new(method, expect, response.code, response_headers.to_hash, response_body, response.timed_out?) + if defined?(Rails) + Rails.logger.error "[zephyr]: #{ failed_request }" + end + raise failed_request end end def create_request_headers(hash) h = Headers.new