Skip to content

Commit

Permalink
catch NotImplementedError and map for older Ruby
Browse files Browse the repository at this point in the history
  • Loading branch information
helenye-stripe committed Jan 13, 2025
1 parent 6c2f861 commit ca96e72
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion lib/stripe/stripe_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ def self.client_init(config_opts)
imported_options = USER_CONFIGURABLE_GLOBAL_OPTIONS - StripeClient::CLIENT_OPTIONS
client_config = StripeConfiguration.setup do |instance|
imported_options.each do |key|
instance.public_send("#{key}=", global_config.public_send(key)) if global_config.respond_to?(key)
begin
instance.public_send("#{key}=", global_config.public_send(key)) if global_config.respond_to?(key)
rescue NotImplementedError => e
# In Ruby <= 2.5, we can't set write_timeout on Net::HTTP, log an error and continue
Util.log_error("Failed to set #{key} on client configuration: #{e}")
end
end
end
client_config.reverse_duplicate_merge(config_opts)
Expand Down
2 changes: 1 addition & 1 deletion test/stripe/stripe_configuration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class StripeConfigurationTest < Test::Unit::TestCase

context "client_init" do
setup do
@client_opts = StripeClient::CLIENT_OPTIONS.to_h { |k| [k, nil] }
@client_opts = Hash[StripeClient::CLIENT_OPTIONS.map { |k| [k, nil] }]
@old_api_key = Stripe.api_key
@old_stripe_account = Stripe.stripe_account
@old_enable_telemetry = Stripe.instance_variable_get(:@enable_telemetry)
Expand Down

0 comments on commit ca96e72

Please sign in to comment.