'92% error rate with Stripe webhooks, unpredictable response

I'm setting up Stripe webhooks for the first time. I've made dozens of test requests and I've had an error rate of 92%. It's unpredictable as to why the failures occur.

The failure responses on the dashboard are either:

Timed out connecting to remote host

or

Failed to connect to remote host

My webhook (I've simplified it for testing). 8% of the time, I get a 200 response with {received: true}:

expressRouter.route('/hooks').post( async (req, res) => {

  const event = req.body;

  console.log("Event:");
  console.log(event);

  // Handle the event
  switch (event.type) {
    case 'payment_intent.succeeded':
      const paymentIntent = event.data.object;
      // Then define and call a method to handle the successful payment intent.
      // handlePaymentIntentSucceeded(paymentIntent);
      break;
    case 'payment_method.attached':
      const paymentMethod = event.data.object;
      // Then define and call a method to handle the successful attachment of a PaymentMethod.
      // handlePaymentMethodAttached(paymentMethod);
      break;
    // ... handle other event types
    default:
      console.log(`Unhandled event type ${event.type}`);
  }

  // Return a response to acknowledge receipt of the event
  res.json({received: true});
})

I have added Stripe's IPs to iptables. I'm running my server with Caddy on Ubuntu 18.04. Any advice is greatly appreciated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source