_generateConnectionError

stripe-node · payments, connection-errors, timeout-handling, http-client

Creates a StripeConnectionError from HTTP client errors, distinguishing timeouts from other connection failures to provide clear error messages.

  static _generateConnectionError(
    error: HttpClientResponseError | HttpClientResponseBodyError,
    timeout: number,
    requestRetries: number,
    // Only available when the failure happened after the headers arrived.
    requestId?: string
  ): StripeConnectionError {
    const isTimeoutError =
      !!error.code && error.code === HttpClient.TIMEOUT_ERROR_CODE;

    return new StripeConnectionError({
      message: isTimeoutError
        ? `Request aborted due to timeout being reached (${timeout}ms)`
        : RequestSender._generateConnectionErrorMessage(requestRetries),
      detail: error,
      requestId,
    });
  }

See the full source, get the GitHub permalink, and search 40K more like it.

Get a free API key