Skip to content

Requests not Throwing Errors in NestJS App or AWS Lambda Node 20/18.x #2231

Open
@Marlrus

Description

@Marlrus

Describe the bug

Within NestJS, when performing calls such as StripeClient.invoices.create or other operations with bad data, requests hang indefinitely and don't throw errors.

To Reproduce

  1. Instantiate Stripe Client with new Stripe(<API_KEY>)
  2. Wrap API call in try/catch block
  3. Call invoices.create method with an invalid payload (Such as the one in the snippet)
  4. Call will hang indefinitely neither erroring or succeeding

Expected behavior

When an API call fails on any non 2xx status, it should throw an exception that can be caught by a try/catch block or a .catch.

Code snippets

// Inside of Controller/Service/Injectable Service
const StripeClient = new Stripe('<API_KEY>');

try {
  const res = await StripeClient.invoices.create({
    customer: 'non-existent-id',
    collection_method: 'send_invoice',
    days_until_due: 14,
    description: 'desc',
    payment_settings: {
      payment_method_types: ['us_bank_account'],
    },
  });

  console.log(res);
} catch (err) {
  console.error(err);
}

OS

Running on Docker linux/amd64 node:20-alpine

Node version

Node v20.18.0

Library version

stripe node version 17.3.0

API version

Default (Whatever you get when you don't specify any)

Additional context

Noticed running in a NestJS Application running in docker.

I've tried:

  • Running requests through an Injectable Service that instantiates Stripe
  • Running the client directly in the Controller, or Service
  • Attempting to pass httpClient property in new Stripe with Axios and NestJS default HTTP Clients, to no avail.

I also tried writing a script with the exact same code on the exact same version of node on a loose .ts file and running it with ts-node and it worked.

I'll keep plowing through as it is critical for me to know when Stripe operations fail. If I find a solution, I will post it here.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions