lib/watchdocs/rails/middleware.rb in watchdocs-rails-0.11.1 vs lib/watchdocs/rails/middleware.rb in watchdocs-rails-0.11.2

- old
+ new

@@ -12,11 +12,11 @@ end def call(env) app.call(env).tap do |response| begin - if json_response?(response) + if record_response?(response) clear_report catch_request(env) catch_response(response) match_endpoint_pattern record_call @@ -27,12 +27,20 @@ end end private - def json_response?(response) - headers = response.second + def record_response?(response) + status, headers, _body = *response + no_content_response?(status) || json_response?(headers) + end + + def no_content_response?(status) + status.to_i == 204 + end + + def json_response?(headers) headers['Content-Type'] && headers['Content-Type'].include?('json') end def clear_report @report = {} @@ -59,11 +67,9 @@ @report[:endpoint] = begin ::Rails.application.routes.router.routes .simulator.memos(report[:request][:url]) .last.path.spec.to_s.sub('(.:format)', '') end - rescue - @report[:endpoint] = 'No routes match' end def record_call Rails::Recordings.record( report, from_specs: from_specs?