#connectplatform-ruby-requestid

1 messages · Page 1 of 1 (latest)

warm rivet
#

Hey @fluid nest. Let me show you a few things

#

We put the request id in the exception too but I need to remember where, let me check

fluid nest
#

We just want to log it

warm rivet
#

sure but to log it you need to access it :p

#

yeah okay if you log the whole exception it has the request id!

#

I just tried and I got Error is: (Status 402) (Request req_123) Your card was declined. for puts "Error is: #{e}" so what you have should work

fluid nest
#

koopajah, is StandardError sufficient to cover all cases or do we need other things in the rescue block. For me in the CLI, I get this for e in the rescue block and there is no request id.

e:
irb(main):023:0> e
=> #<Stripe::PermissionError: (Status 403) The provided key 'sk_live_**************' does not have access to account 'acct_xxxxxxxxxx' (or that account does not exist). Application access may have been revoked.>

#

e.message is the same as e and
e.request_id is nil

irb(main):025:0> e.request_id
=> nil

warm rivet
#

yeah you're misunderstanding most of what I said I think

#

there's no request_id property on that exception, it appears when you log the exception itself, and you want to catch a Stripe exception

#
begin
  pi = Stripe::PaymentIntent.create({
    amount: 2000,
    currency: 'usd',
    payment_method_types: ['card'],
    payment_method: 'pm_card_chargeDeclined',
    confirm: true
  })
rescue Stripe::StripeError => e
  puts "Error is: #{e.error.message}"
  puts "Error is: #{e}"
end``` try that code for example
fluid nest
#

Sorry, man, I don't see a request id.

#

begin
customer = Stripe::Customer.retrieve(stripe_connect_customer_id, :stripe_account => @site.stripe_user_id)
rescue Stripe::StripeError => e
Rails.logger.warn "StandardError => e: #{e}"
Rails.logger.warn "StandardError => e.error: #{e.error}"
Rails.logger.warn "StandardError => e.error.message: #{e.error.message}"
end

#

That is a failing API call

#

I see now the e.error has some good data....but I do not see the request id even when we use Stripe::StripeError => e

#

I would love a key that is request_id but do not see it

#

i see code, doc_url, message, and type but no request_id?

warm rivet
#

hum

fluid nest
#

old API?

warm rivet
#

how do you trigger that error exactly?

#

also why not test in test mode like all devs 😅

fluid nest
#

i could. this was an actual strange error in production i'm debugging. My developer has a test account set up in production and connected to Stripe and was on a fake active site but I guess we deauthroized him so we are making an API call to a connected account that has deauthorized. I was just in the midst of figuring out why the job was throwing an error and had it up in my CLI so was using that as the example. I just want to return from that error since it may happen again and muddies the waters so I want to log the request ID and return.

#

API call fails since the connect account has deauthorized but we still have in our db that he is active.
customer = Stripe::Customer.retrieve(stripe_connect_customer_id, :stripe_account => @site.stripe_user_id)

#

We try to get a customer on the connected account.

#

And get a
Stripe::PermissionError: (Status 403)

warm rivet
#

Okay so I think those requests do not create a request id

fluid nest
#

because it is connnect?

warm rivet
#

because they can't succeed at all as you have no permissions on the account

fluid nest
#

aha. got it. We will just log the message.

#

ok

warm rivet
#

It's like passing the wrong API key. We don't know which account you are since your key is wrong, so we can error but there's no req_123

fluid nest
#

aha!

warm rivet
#

same for "Rate limits" we just error way before we start logging the requests

#

does that make sense?

fluid nest
#

totally! got it.

warm rivet
#

I'd say try a card error and a 404 (like retrieve cus_fakefakefake) and those should have the req_123