
Security News
Open Source CAI Framework Handles Pen Testing Tasks up to 3,600× Faster Than Humans
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
fetch-timeout
Advanced tools
HTTP/S fetch wrapper that adds the possibility to set a timeout after which a custom error is returned.
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.
npm install --save fetch-timeout
Also add the following package, since the standard window.fetch isn't accessible from node.
npm install --save node-fetch
var fetchTimeout = require('fetch-timeout');
fetchTimeout('https://api.github.com/', {
method: 'GET',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
}, 5000, 'My custom timeout error string')
.then(function(res) {
if (res.status !== 200) {
throw new Error('Status code not OK', res.status);
} else {
return res.json();
}
})
.then(function(json) {
console.log("json returned from response");
})
.catch(function(err) {
console.log("error", err);
});
import fetchTimeout from 'fetch-timeout';
fetchTimeout('https://api.github.com/', {
method: 'GET',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
}, 5000, 'My custom timeout error string')
.then(res => {
if (res.status !== 200) {
throw new Error('Status code not OK', res.status);
} else {
return res.json();
}
})
.then(json => {
console.log("json returned from response");
})
.catch(err => {
console.log("error", err);
});
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 |
npm test
Pull requests and suggestions are more than welcome!
FAQs
HTTP/S fetch wrapper that adds the possibility to set a timeout after which a custom error is returned.
The npm package fetch-timeout receives a total of 209 weekly downloads. As such, fetch-timeout popularity was classified as not popular.
We found that fetch-timeout demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
Security News
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.