Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fetchres

Package Overview
Dependencies
Maintainers
2
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

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.

  • 1.6.2
  • npm
  • Socket score

Version published
Weekly downloads
1.7K
increased by84.1%
Maintainers
2
Weekly downloads
 
Created
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

Package last updated on 09 Nov 2016

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