isomorphic-fetch-reject

1.0.1 • Public • Published

isomorphic-fetch-reject

This package is using isomorphic-fetch and extends it to reject on HTTP error.

Standard fetch does not throw on HTTP errors (>= 400 status code). This wrapper allows it to do so.

This package is perfect for apps that render on both the server and the client side.

Install

npm i -S isomorphic-fetch-reject
yarn add isomorphic-fetch-reject

Usage

You can either use it like any other package:

import fetch from 'isomorphic-fetch-reject';
 
// Use just like the standard fetch
fetch('https://example.com/some/path')
  .then(res => res.json())
  .then(data => {
    console.log(data);
  })
  .catch(err => {
    console.error(err);
  });

Or you can add the fetch function directly to the global/window so you can use it from anywhere:

// file1.js
import fetch from 'isomorphic-fetch-reject';
fetch.replaceGlobal();
// file2.js
// Use just like the standard fetch
fetch('https://example.com/some/path')
  .then(res => res.json())
  .then(data => {
    console.log(data);
  })
  .catch(err => {
    console.error(err);
  });

Readme

Keywords

none

Package Sidebar

Install

npm i isomorphic-fetch-reject

Weekly Downloads

76

Version

1.0.1

License

MIT

Unpacked Size

3.19 kB

Total Files

4

Last publish

Collaborators

  • imperium02
  • davethemac
  • mkredz
  • fbarbare
  • dave-hillier
  • missbruni
  • rameshanandakrishnan
  • pbazydlo
  • guru_fordy
  • greg.plenzler
  • rachel.sinclair