Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deletion commands do not work via fetch #1360

Closed
CraigglesO opened this issue Feb 26, 2022 · 4 comments · Fixed by #1388 · 4 remaining pull requests
Closed

Deletion commands do not work via fetch #1360

CraigglesO opened this issue Feb 26, 2022 · 4 comments · Fixed by #1388 · 4 remaining pull requests

Comments

@CraigglesO
Copy link

NodeJS version: v16.13.2
Stripe version: ^8.197.0

I am using a cloudflare worker, so if you check the webpack config here you can see it is limiting stripe to fetch and building like so:

const STRIPE = Stripe(STRIPE_API_CODE, { httpClient: Stripe.createFetchHttpClient() })

commands like await STRIPE.customers.deleteTaxId and await STRIPE.customers.del do not work. An example error is as follows:

Zo [Error]: An error occurred with our connection to Stripe.
    at /Users/ct/Documents/Projects/node_modules/.pnpm/stripe@8.202.0/node_modules/stripe/lib/StripeResource.js:519:15
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  type: 'Zo',
  raw: {
    message: 'An error occurred with our connection to Stripe.',
    detail: TypeError: fetch failed
        at Object.processResponse (/Users/ct/.npm/_npx/dce38835dbc726fc/node_modules/undici/lib/fetch/index.js:183:23)
        at Fetch.fetchFinale (/Users/ct/.npm/_npx/dce38835dbc726fc/node_modules/undici/lib/fetch/index.js:937:17)
        at Fetch.mainFetch (/Users/ct/.npm/_npx/dce38835dbc726fc/node_modules/undici/lib/fetch/index.js:744:17)
        at processTicksAndRejections (node:internal/process/task_queues:96:5) {
      cause: [RequestContentLengthMismatchError]
    }
  },
  rawType: undefined,
  code: undefined,
  doc_url: undefined,
  param: undefined,
  detail: TypeError: fetch failed
      at Object.processResponse (/Users/ct/.npm/_npx/dce38835dbc726fc/node_modules/undici/lib/fetch/index.js:183:23)
      at Fetch.fetchFinale (/Users/ct/.npm/_npx/dce38835dbc726fc/node_modules/undici/lib/fetch/index.js:937:17)
      at Fetch.mainFetch (/Users/ct/.npm/_npx/dce38835dbc726fc/node_modules/undici/lib/fetch/index.js:744:17)
      at processTicksAndRejections (node:internal/process/task_queues:96:5) {
    cause: RequestContentLengthMismatchError: Request body length does not match content-length header
        at write (/Users/ct/.npm/_npx/dce38835dbc726fc/node_modules/undici/lib/client.js:1432:37)
        at _resume (/Users/ct/.npm/_npx/dce38835dbc726fc/node_modules/undici/lib/client.js:1384:29)
        at resume (/Users/ct/.npm/_npx/dce38835dbc726fc/node_modules/undici/lib/client.js:1243:3)
        at processTicksAndRejections (node:internal/process/task_queues:82:21) {
      code: 'UND_ERR_REQ_CONTENT_LENGTH_MISMATCH'
    }
  },
  headers: undefined,
  requestId: undefined,
  statusCode: undefined,
  charge: undefined,
  decline_code: undefined,
  payment_intent: undefined,
  payment_method: undefined,
  payment_method_type: undefined,
  setup_intent: undefined,
  source: undefined
}

I believe RequestContentLengthMismatchError is the key to this error.

@jnordberg
Copy link

I'm also running into something similar to this, not for delete requests though. I think the issue is that the stripe lib sets content-length to 0 for empty requests and the fetch implementation by Cloudflare uses undici which doesn't allow that. Not sure if the Cloudflare fetch wrapper is doing something wrong or most other http client implementations choose to fix that for you instead of bombing like undici does, it's a bit silly IMO.

I think this has to be addressed in wrangler or wherever that fetch > undici bridge lives

@jnordberg
Copy link

Seems this has been fixed in miniflare 2.4.0 (not published to npm yet, probably will be soon): cloudflare/miniflare#193

@CraigglesO
Copy link
Author

Just incase stripe is ok with this fix:
#1370

@dcr-stripe
Copy link
Contributor

dcr-stripe commented Mar 31, 2022

Thanks for the detailed report! We've fixed this in #1388 and will be rolling this out as part of the next release. Sorry for the trouble here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment