New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@akiyamka/extended-fetch

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@akiyamka/extended-fetch

![NPM Version](https://img.shields.io/npm/v/%40akiyamka%2Fextended-fetch) ![NPM Type Definitions](https://img.shields.io/npm/types/%40akiyamka%2Fextended-fetch) [![spring-easing's badge](https://deno.bundlejs.com/badge?q=@akiyamka/extended-fetch@0.0.5&tre

  • 0.0.7
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
57
increased by7.55%
Maintainers
1
Weekly downloads
 
Created
Source

extended-fetch

NPM Version NPM Type Definitions spring-easing's badge Module type: ESM Module type: CJS
Tiny window.fetch JavaScript implementation without over XMLHttpRequest with additional features
Can be used ds drop in replacement for fetch

Installation

npm install @akiyamka/extended-fetch

Usage

Works just like native fetch, but with few additional features:

Catch timeout error

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);
});

Subscribe to xhr events:

Also you can hook XMLHttpRequest events:

fetch(
  '/users',
  {
    method: 'POST',
    body: JSON.stringify({ foo: 'bar' }),
  },
  {
    // Extra setting
    eventListener: (event) => {
      if (event.type === 'progress') {
        console.log(`Progress changed to ${event.payload}`);
      }
    },
  }
).catch((error) => {
  // Allow identify timeout error
  console.assert(error.message, 'Timeout Error');
  console.assert(isTimeoutError(error), true);
});

Credits

Inspired by https://github.com/JakeChampion/fetch

Keywords

FAQs

Package last updated on 30 Apr 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc