Merge pull request #408 from stripe/karla-openssl-errors

Catch SSL connection errors, and re-raise them as APIConnectionErrors
This commit is contained in:
Karla 2016-04-11 10:39:13 -07:00
commit cb734cfeac
2 changed files with 20 additions and 1 deletions

View File

@ -208,7 +208,7 @@ module Stripe
else
response = handle_restclient_error(e, request_opts, retry_count, api_base_url)
end
rescue RestClient::Exception, Errno::ECONNREFUSED => e
rescue RestClient::Exception, Errno::ECONNREFUSED, OpenSSL::SSL::SSLError => e
response = handle_restclient_error(e, request_opts, retry_count, api_base_url)
end
@ -384,6 +384,12 @@ module Stripe
message = "The connection to the server (#{api_base_url}) broke before the " \
"request completed. #{connection_message}"
when OpenSSL::SSL::SSLError
message = "Could not establish a secure connection to Stripe, you may " \
"need to upgrade your OpenSSL version. To check, try running " \
"'openssl s_client -connect api.stripe.com:443' from the " \
"command line."
when RestClient::SSLCertificateNotVerified
message = "Could not verify Stripe's SSL certificate. " \
"Please make sure that your network is not intercepting certificates. " \

View File

@ -695,6 +695,19 @@ module Stripe
assert_equal "myid", result.id
end
# We retry the request if we receive SSL errors, since these can be caused
# by transient network issues, in addition to compatibility issues between
# the client and server.
should 'retry failed network requests if they fail with OpenSSL::SSL::SSLError' do
Stripe.expects(:sleep_time).at_least_once.returns(0)
@mock.expects(:post).times(3).with('https://api.stripe.com/v1/charges', nil, 'amount=50&currency=usd').raises(OpenSSL::SSL::SSLError.new('message'))
err = assert_raises Stripe::APIConnectionError do
Stripe::Charge.create(:amount => 50, :currency => 'usd', :card => { :number => nil })
end
assert_match(/Request was retried 2 times/, err.message)
end
should 'not retry a SSLCertificateNotVerified error' do
@mock.expects(:post).times(1).with('https://api.stripe.com/v1/charges', nil, 'amount=50&currency=usd').raises(RestClient::SSLCertificateNotVerified.new('message'))