Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
@akiyamka/extended-fetch
Advanced tools
Tiny window.fetch JavaScript implementation over XMLHttpRequest with additional features
Currently, there is no way to determine that the reason the request failed is due to the Timeout Error using the fetch API, but sometimes it needed, for example, for meaningful UI reaction.
The most popular workaround for this today is to set a forced limit on the client side, which will only work if it less than the existing limit outside, and it will also break functionality in situations where the limit has been raised above the standard limit
This library allows you to cath Timeout Error without enforcing a time restriction
🤏 Tiny size
🧩 Does not patching existing fetch, just exports own implementation
🔀 Can be used as drop in replacement for fetch
⚠️ It's not a fetch polyfill. It uses
Request
andResponse
objects from fetch implementation
npm install @akiyamka/extended-fetch
Works just like native fetch, but with few additional features:
Fetch does not allow the user to know if his request was failed due to a 504 error.
Instead it throws common TypeError: Failed to fetch
But extended-fetch
throw 'Timeout Error' error for that case
import { fetch, isTimeoutError } from 'extended-fetch';
fetch('/users', {
method: 'POST',
body: JSON.stringify({ foo: 'bar' }),
}).catch((error) => {
// Allow identify timeout error
console.assert(error.message, 'Timeout Error');
console.assert(isTimeoutError(error), true);
});
Also you can hook XMLHttpRequest events:
import { fetch } from 'extended-fetch';
fetch(
'/users',
{
method: 'POST',
body: JSON.stringify({ foo: 'bar' }),
},
{
// Extra setting
eventListener: (event) => {
if (event.type === 'progress') {
console.log(`Progress changed to ${event.payload}`);
}
},
}
)
The library has a typed helper for Abort error detection
import { fetch, isAbortError } from 'extended-fetch';
const abortController = new AbortController()
abortController.abort()
try {
const reference = await fetch(srv.readyCheck(), {
signal: abortController.signal,
})
} catch(err) {
if (isAbortError(e)) {
// request was aborted
}
}
Inspired by https://github.com/JakeChampion/fetch
FAQs
Tiny window.fetch JavaScript implementation over XMLHttpRequest with additional features
The npm package @akiyamka/extended-fetch receives a total of 16 weekly downloads. As such, @akiyamka/extended-fetch popularity was classified as not popular.
We found that @akiyamka/extended-fetch demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.