#manish_api

1 messages ¡ Page 1 of 1 (latest)

dry windBOT
#

👋 Welcome to your new thread!

⏲️ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

⏱️ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

🔗 This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1243534595966631937

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

small boneBOT
#

Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

vital vault
#

Hi

the subsequent requests returns the last response instead of throwing an error
The requestId you've shared did return an error with http status 409

meager lava
#

yea i can see that in logs, but it does not goes to the catch block in my code, it will just return the last successfull response

vital vault
#

Have you had the chance to debug your code or add some log line ?

#

like log the requestId and the corresponding response status for example

meager lava
vital vault
#

You are seeing two lines with different requestId and same http status ?

#

yea i tried
Can you then share the two requestId and what was the response status your sdk displayed ?

meager lava
#

the sdk returned this

{
  id: 'cus_QAHK8vmxDMWMaZ',
  object: 'customer',
  address: null,
  balance: 0,
  created: 1716551921,
  currency: null,
  default_source: null,
  delinquent: false,
  description: null,
  discount: null,
  email: null,
  invoice_prefix: '341C5499',
  invoice_settings: {
    custom_fields: null,
    default_payment_method: null,
    footer: null,
    rendering_options: null
  },
  livemode: false,
  metadata: {},
  name: 'Hopstack 1',
  next_invoice_sequence: 1,
  phone: null,
  preferred_locales: [],
  shipping: null,
  tax_exempt: 'none',
  test_clock: null
}
THEN BLOCK
{
  id: 'cus_QAHK8vmxDMWMaZ',
  object: 'customer',
  address: null,
  balance: 0,
  created: 1716551921,
  currency: null,
  default_source: null,
  delinquent: false,
  description: null,
  discount: null,
  email: null,
  invoice_prefix: '341C5499',
  invoice_settings: {
    custom_fields: null,
    default_payment_method: null,
    footer: null,
    rendering_options: null
  },
  livemode: false,
  metadata: {},
  name: 'Hopstack 1',
  next_invoice_sequence: 1,
  phone: null,
  preferred_locales: [],
  shipping: null,
  tax_exempt: 'none',
  test_clock: null
}

couldnt find the requestId in its response

vital vault
#

You need to inspect the header of the http response

#

From where you got this requestId req_QzRkODbWMHMEZk ?

meager lava
#

from dashboard logs

vital vault
#

How many requests you are sending during your test ?

meager lava
#

while testing the indempotency i sent only two

vital vault
#

Ok, I see that there were 3 requests actually with the same timestamp

meager lava
#

in dashboard logs it shows it has returned error, but sdk is not rejecting the promise

#

if you want i can again send 2 requests

vital vault
#

First one: req_Hk1z7GH1cnyORI
Second: req_QzRkODbWMHMEZk (with the error)
Third: req_ySRwboA8NBt4EP responded correctly which prints the correct result

#

if you want i can again send 2 requests
Yes please send just 2 other requests with a new idempotency key

#

and let me know to re-check

meager lava
#

okay give me 2 minutes

#

successfull: req_XdHxuSQe2f8GCe
Failed: req_kXJNGuAnaAlGTc

#

SDK response

{
  id: 'cus_QAHcWj2W68oddo',
  object: 'customer',
  address: null,
  balance: 0,
  created: 1716553023,
  currency: null,
  default_source: null,
  delinquent: false,
  description: null,
  discount: null,
  email: null,
  invoice_prefix: '0BFDF721',
  invoice_settings: {
    custom_fields: null,
    default_payment_method: null,
    footer: null,
    rendering_options: null
  },
  livemode: false,
  metadata: {},
  name: 'Test with stripe',
  next_invoice_sequence: 1,
  phone: null,
  preferred_locales: [],
  shipping: null,
  tax_exempt: 'none',
  test_clock: null
}
{
  id: 'cus_QAHcWj2W68oddo',
  object: 'customer',
  address: null,
  balance: 0,
  created: 1716553023,
  currency: null,
  default_source: null,
  delinquent: false,
  description: null,
  discount: null,
  email: null,
  invoice_prefix: '0BFDF721',
  invoice_settings: {
    custom_fields: null,
    default_payment_method: null,
    footer: null,
    rendering_options: null
  },
  livemode: false,
  metadata: {},
  name: 'Test with stripe',
  next_invoice_sequence: 1,
  phone: null,
  preferred_locales: [],
  shipping: null,
  tax_exempt: 'none',
  test_clock: null
}
vital vault
#

No I see 3 requests

meager lava
#

yea me too

vital vault
#
  1. req_3FCwBmlQPYfNmY
  2. req_kXJNGuAnaAlGTc
  3. req_XdHxuSQe2f8GCe
#

So your integration is sending 3 requests and not 2.

meager lava
#

yea just checked the logs there are three requests

vital vault
#

The one is returning an error is being retried apparently from your integration

meager lava
#
stripe.customers
      .create(
        { name: "Test with stripe" },
        {
          idempotencyKey: uniqueKey,
        }
      )
      .then(result => {
        console.dir(result, { depth: null });
      })
      .catch(error => {
        console.error("ERROR BLOCK");
        console.dir(error, { depth: null });
      });
#

in my code i have just executed the block above twice

#

if in background somehow it ran 3 times it should return error for 1 request which failed

vital vault
#

THere must be some catch/retry in your code/integration

#

Between, I'm not seeing any issue, the retru meecanisme working fine in your integration and you are creating one single Customer

#

from 3 requests with the same idempotency key

#

What is the issue here? I'm missing something ?

meager lava
#
import Stripe from "stripe";
import { v4 as uuidv4 } from "uuid";
const stripe = new Stripe(
  "sk_test_sdfgsdfg"
);

    const uniqueKey = uuidv4();

    stripe.customers
      .create(
        { name: "Test with stripe" },
        {
          idempotencyKey: uniqueKey,
        }
      )
      .then(result => {
        console.dir(result, { depth: null });
      })
      .catch(error => {
        console.error("ERROR BLOCK");
        console.dir(error, { depth: null });
      });

this is my complete code

#

The catch block is there but its not coming in that for that failed request

vital vault
#

And how are you sending multiple request ?

#

If you just run the code above, this will send only one request.

meager lava
#

i just copy pasted the stripe.customers.create function

#

so it will look like this

import Stripe from "stripe";
import { v4 as uuidv4 } from "uuid";
const stripe = new Stripe(
  "sk_test_sdfgsdfg"
);

    const uniqueKey = uuidv4();

    stripe.customers
      .create(
        { name: "Test with stripe" },
        {
          idempotencyKey: uniqueKey,
        }
      )
      .then(result => {
        console.dir(result, { depth: null });
      })
      .catch(error => {
        console.error("ERROR BLOCK");
        console.dir(error, { depth: null });
      });
    stripe.customers
      .create(
        { name: "Test with stripe" },
        {
          idempotencyKey: uniqueKey,
        }
      )
      .then(result => {
        console.dir(result, { depth: null });
      })
      .catch(error => {
        console.error("ERROR BLOCK");
        console.dir(error, { depth: null });
      });
vital vault
meager lava
#

but log shows 409 error

vital vault
#

Yes it's the same subcategroy of request.

#

You are making two requests and the SDK is sending 3 requests (2 request with one automatically retried)

meager lava
#

even if it retries the key should remain the same right?

vital vault
#

The idempotency key you mean? yes the same will be used.

meager lava
#

but if you see the customers list there is only one customer with that name, despite of having 3 requests

vital vault
#

The 3 requests with the same idempotency key, will create only 1 customer.

meager lava
#

ahhh
how do i ensure that i receive that error message?

vital vault
#

No you won't, unless you set setMaxNetworkRetries to 0 I think

#

Why you want to get that error message between ? to do what exactly ?

meager lava
#

we have our own retry mechanism and stuff so this can create confusion

meager lava
meager lava
#

Thanks for help
you can close the thread