fetch-timeout
HTTP/S fetch wrapper that adds the possibility to set a timeout after which a custom error is returned. If used in NodeJS, this package is dependent on node-fetch, altough it will always try to use window.fetch.
Installation
npm install --save fetch-timeout
Nodejs environment only
Also add the following package, since the standard window.fetch isn't accessible from node.
npm install --save node-fetch
Usage
ES5
var fetchTimeout = ; ;
ES6
; ;
API
Arguments | Type | Optional | Default | Description |
---|---|---|---|---|
url | string | false | url to pass to node-fetch | |
options | object | true | {} | standard options to pass to node-fetch |
timeout | number | true | 10000 | maximum acceptable timeout before throwing the timeout error |
error | string | true | 'Timeout error' | custom error string after the timeout is expired |
Tests
npm test
Contributing
Pull requests and suggestions are more than welcome!