mirror of
https://github.com/stripe/stripe-ruby.git
synced 2025-11-30 00:00:47 -05:00
Merge pull request #408 from stripe/karla-openssl-errors
Catch SSL connection errors, and re-raise them as APIConnectionErrors
This commit is contained in:
commit
cb734cfeac
@ -208,7 +208,7 @@ module Stripe
|
|||||||
else
|
else
|
||||||
response = handle_restclient_error(e, request_opts, retry_count, api_base_url)
|
response = handle_restclient_error(e, request_opts, retry_count, api_base_url)
|
||||||
end
|
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)
|
response = handle_restclient_error(e, request_opts, retry_count, api_base_url)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -384,6 +384,12 @@ module Stripe
|
|||||||
message = "The connection to the server (#{api_base_url}) broke before the " \
|
message = "The connection to the server (#{api_base_url}) broke before the " \
|
||||||
"request completed. #{connection_message}"
|
"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
|
when RestClient::SSLCertificateNotVerified
|
||||||
message = "Could not verify Stripe's SSL certificate. " \
|
message = "Could not verify Stripe's SSL certificate. " \
|
||||||
"Please make sure that your network is not intercepting certificates. " \
|
"Please make sure that your network is not intercepting certificates. " \
|
||||||
|
|||||||
@ -695,6 +695,19 @@ module Stripe
|
|||||||
assert_equal "myid", result.id
|
assert_equal "myid", result.id
|
||||||
end
|
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¤cy=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
|
should 'not retry a SSLCertificateNotVerified error' do
|
||||||
@mock.expects(:post).times(1).with('https://api.stripe.com/v1/charges', nil, 'amount=50¤cy=usd').raises(RestClient::SSLCertificateNotVerified.new('message'))
|
@mock.expects(:post).times(1).with('https://api.stripe.com/v1/charges', nil, 'amount=50¤cy=usd').raises(RestClient::SSLCertificateNotVerified.new('message'))
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user