Package Exports
- timeout-fetch
- timeout-fetch/src/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (timeout-fetch) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Timeout Fetch
Creates an instance of fetch that aborts after a certain time period.
import timeoutFetch, { TimeoutError } from 'timeout-fetch';
import nodeFetch from 'node-fetch';
// Timeout is defined in miliseconds
const ONE_SECOND = 1000;
const fetch = timeoutFetch(
ONE_SECOND,
nodeFetch // Defaults to globalThis.fetch if you don't provide a fetch implementation yourself
);
try {
await fetch('http://example.com');
console.log('Fetch success');
} catch(e) {
if(e instanceof TimeoutError) {
console.log('Fetch timed out');
} else {
console.log('Another error occured');
}
}
Dependencies
timeout-fetch
Timeout Fetch
See: module:timeout-fetch.default
- timeout-fetch
- module.exports(count, fetch) ⇒
function
⏏
- module.exports(count, fetch) ⇒
module.exports(count, fetch) ⇒ function
⏏
Creates a fetch function that is aborted after a timeout period
Kind: Exported function
Returns: function
- The created fetch function. Has the same signature as the passed param.
Param | Type | Description |
---|---|---|
count | number |
The timeout duration in miliseconds |
fetch | function |
The fetch function to call, defaults to the global fetch |
module.exports.TimeoutError
Error that is thrown when the timeout expires
Kind: static class of module.exports