Socket
Socket
Sign inDemoInstall

fetchres

Package Overview
Dependencies
0
Maintainers
2
Versions
28
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    fetchres

Some useful response handlers for using [Fetch](https://github.com/github/fetch) API in the real world.


Version published
Weekly downloads
593
increased by5.7%
Maintainers
2
Install size
13.9 kB
Created
Weekly downloads
 

Readme

Source

fetchres Build Status

Some useful response handlers for using Fetch API in the real world.

Warning: doesn't come with Fetch or Promise, so you'll need to bring your own polyfill (unless you're using this module within Service Workers, where both fetch and Promise are already defined).

Installation

npm install --save fetchres

Or

bower install --save fetchres

Usage (node)

var fetchres = require('fetchres');

fetch('https://mattandre.ws/my-json-endpoint')
	.then(fetchres.json)
	.then(function(data) {
		// `data` is an object containing the data
		// from the response, not a Response object
		console.log(data);
	})
	.catch(function(err) {
		if (err.name === fetchres.BadServerResponseError.name) {
			// just a dodgy response
			console.error(err);
		} else if (err.name === fetchres.InvalidJsonError.name) {
			// malformed json, probably
			console.error('malformed json returned');
		} else {
			// something more serious could be wrong.
			// probably want to investigate / send to
			// error aggregation service
			debugger;
		}
	});

FAQs

Last updated on 09 Nov 2016

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc