diff --git a/CHANGELOG.md b/CHANGELOG.md index ce813dfc9..7eab3e355 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ Changelog - [patch] Improve error message for syntax error in ERB-using cassettes (#909) - [patch] Handle `use_cassette(..., erb: {})` (#908) - [fix] Use fiber-local for `global_hook_disabled_requests` (#907) +- [fix] Dont attempt to parse a nil response when hooking into `:excon` (#916) ## 6.0.0 (May 28, 2020) [Full Changelog](https://github.com/vcr/vcr/compare/v5.1.0...v6.0.0) diff --git a/lib/vcr/middleware/excon.rb b/lib/vcr/middleware/excon.rb index 9eb6d7dad..22b17aace 100644 --- a/lib/vcr/middleware/excon.rb +++ b/lib/vcr/middleware/excon.rb @@ -74,7 +74,7 @@ def before_request(request_params) def after_request(response) vcr_response = vcr_response_for(response) - if should_record? + if vcr_response && should_record? VCR.record_http_interaction(VCR::HTTPInteraction.new(vcr_request, vcr_response)) end diff --git a/spec/lib/vcr/library_hooks/excon_spec.rb b/spec/lib/vcr/library_hooks/excon_spec.rb index 8ef8c89c8..b7623a6c2 100644 --- a/spec/lib/vcr/library_hooks/excon_spec.rb +++ b/spec/lib/vcr/library_hooks/excon_spec.rb @@ -45,6 +45,26 @@ def make_request end end + context "when Excon raises an internal error before body is processed" do + let(:excon) { ::Excon.new('https://expired.badssl.com') } + let(:ssl_error) { OpenSSL::SSL::SSLError.new("SSL_connect returned=1 errno=0 state=error: certificate verify failed (certificate has expired)") } + + before do + allow(excon).to receive(:socket) { raise ssl_error } + end + + def make_request + VCR.use_cassette('with_errors', :record => :once) do + excon.request(method: :get, :expects => [200]) + end + end + + it 'raises SSL errors and does not try to record a cassette' do + expect(VCR).to_not receive(:record_http_interaction) + expect { make_request }.to raise_error(Excon::Error::Certificate) + end + end + include_examples "Excon streaming" context 'when Excon raises an error due to an unexpected response status' do