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

Change timeout default to constant 80000 instead Node default #807

Merged
merged 1 commit into from
Feb 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,15 @@ const stripe = Stripe('sk_test_...', {
});
```

| Option | Default | Description |
| ------------------- | ----------------------------- | ------------------------------------------------------------------------------------- |
| `apiVersion` | `null` | Stripe API version to be used. If not set the account's default version will be used. |
| `maxNetworkRetries` | 0 | The amount of times a request should be [retried](#network-retries). |
| `httpAgent` | `null` | [Proxy](#configuring-a-proxy) agent to be used by the library. |
| `timeout` | 120000 (Node default timeout) | [Maximum time each request can take in ms.](#configuring-timeout) |
| `host` | `'api.stripe.com'` | Host that requests are made to. |
| `port` | 443 | Port that requests are made to. |
| `telemetry` | `true` | Allow Stripe to send latency [telemetry](#request-latency-telemetry). |
| Option | Default | Description |
| ------------------- | ------------------ | ------------------------------------------------------------------------------------- |
| `apiVersion` | `null` | Stripe API version to be used. If not set the account's default version will be used. |
| `maxNetworkRetries` | 0 | The amount of times a request should be [retried](#network-retries). |
| `httpAgent` | `null` | [Proxy](#configuring-a-proxy) agent to be used by the library. |
| `timeout` | 80000 | [Maximum time each request can take in ms.](#configuring-timeout) |
| `host` | `'api.stripe.com'` | Host that requests are made to. |
| `port` | 443 | Port that requests are made to. |
| `telemetry` | `true` | Allow Stripe to send latency [telemetry](#request-latency-telemetry). |

Note: Both `maxNetworkRetries` and `timeout` can be overridden on a per-request basis.

Expand Down
3 changes: 1 addition & 2 deletions lib/stripe.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ const DEFAULT_PORT = '443';
const DEFAULT_BASE_PATH = '/v1/';
const DEFAULT_API_VERSION = null;

// Use node's default timeout:
const DEFAULT_TIMEOUT = require('http').createServer().timeout;
const DEFAULT_TIMEOUT = 80000;

Stripe.PACKAGE_VERSION = require('../package.json').version;

Expand Down
13 changes: 4 additions & 9 deletions test/stripe.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ const utils = require('../lib/utils');
const Stripe = require('../lib/stripe');
const stripe = require('../lib/stripe')(testUtils.getUserStripeKey(), 'latest');

const http = require('http');

const expect = require('chai').expect;

const CUSTOMER_DETAILS = {
Expand Down Expand Up @@ -208,20 +206,17 @@ describe('Stripe Module', function() {
});

describe('setTimeout', () => {
it('Should define a default equal to the node default', () => {
expect(stripe.getApiField('timeout')).to.equal(
http.createServer().timeout
);
const defaultTimeout = 80000;
it('Should define a default of 80000', () => {
expect(stripe.getApiField('timeout')).to.equal(defaultTimeout);
});
it('Should allow me to set a custom timeout', () => {
stripe.setTimeout(900);
expect(stripe.getApiField('timeout')).to.equal(900);
});
it('Should allow me to set null, to reset to the default', () => {
stripe.setTimeout(null);
expect(stripe.getApiField('timeout')).to.equal(
http.createServer().timeout
);
expect(stripe.getApiField('timeout')).to.equal(defaultTimeout);
});
});

Expand Down
2 changes: 1 addition & 1 deletion types/lib.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ declare module 'stripe' {

/**
* Request timeout in milliseconds.
* The default is Node's default of 120 seconds.
* The default is 80000
*/
timeout?: number;

Expand Down