track stripe errors in Datadog so we can alert on them (#5797)
This commit is contained in:
parent
928fdd5ecd
commit
a5dd0c6abb
2 changed files with 27 additions and 0 deletions
|
|
@ -11,9 +11,14 @@ class StripeActiveCardsController < ApplicationController
|
|||
"Your billing information has been updated"
|
||||
else
|
||||
logger.info("Stripe Add New Card Failure - #{current_user.username}")
|
||||
DataDogStatsClient.increment("stripe.errors")
|
||||
redirect_to "/settings/billing", flash: { error:
|
||||
"There was a problem updating your billing info." }
|
||||
end
|
||||
rescue Stripe::InvalidRequestError
|
||||
DataDogStatsClient.increment("stripe.errors")
|
||||
redirect_to "/settings/billing", flash: { error:
|
||||
"There was a problem updating your billing info." }
|
||||
end
|
||||
|
||||
def update
|
||||
|
|
@ -31,6 +36,7 @@ class StripeActiveCardsController < ApplicationController
|
|||
"There was a problem updating your billing info." }
|
||||
end
|
||||
rescue Stripe::CardError => e
|
||||
DataDogStatsClient.increment("stripe.errors")
|
||||
flash[:error] = e.message
|
||||
redirect_to "/settings/billing"
|
||||
end
|
||||
|
|
|
|||
|
|
@ -26,6 +26,27 @@ RSpec.describe "StripeSubscriptions", type: :request do
|
|||
card = Stripe::Customer.retrieve(user.stripe_id_code).sources.first
|
||||
expect(card.is_a?(Stripe::Card)).to eq(true)
|
||||
end
|
||||
|
||||
it "increments sidekiq.errors in Datadog on failure" do
|
||||
allow(DataDogStatsClient).to receive(:increment)
|
||||
invalid_error = Stripe::InvalidRequestError.new(nil, nil)
|
||||
allow(Stripe::Customer).to receive(:create).and_raise(invalid_error)
|
||||
post "/stripe_active_cards", params: { stripe_token: stripe_helper.generate_card_token }
|
||||
expect(DataDogStatsClient).to have_received(:increment).with("stripe.errors")
|
||||
end
|
||||
end
|
||||
|
||||
describe "PUT StripeActiveCards#update" do
|
||||
it "increments sidekiq.errors in Datadog on failure" do
|
||||
valid_instance(user)
|
||||
customer = Stripe::Customer.retrieve(user.stripe_id_code)
|
||||
original_card_id = customer.sources.all(object: "card").first.id
|
||||
allow(DataDogStatsClient).to receive(:increment)
|
||||
card_error = Stripe::CardError.new(nil, nil, nil)
|
||||
allow(Stripe::Customer).to receive(:retrieve).and_raise(card_error)
|
||||
put "/stripe_active_cards/#{original_card_id}", params: {}
|
||||
expect(DataDogStatsClient).to have_received(:increment).with("stripe.errors")
|
||||
end
|
||||
end
|
||||
|
||||
describe "DESTROY StripeActiveCards#destroy" do
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue