isomorphic-fetch-reject
Advanced tools
Comparing version 1.0.0 to 1.0.1
20
index.js
require('es6-promise').polyfill(); | ||
var fetch = require('isomorphic-fetch'); | ||
var fetchReject = require('fetch-reject'); | ||
var newFetch = fetchReject.createFetchReject(fetch); | ||
function onResponse(res) { | ||
if (res.ok) { | ||
return res; | ||
} | ||
var error = new Error(); | ||
error.status = res.status; | ||
error.response = res; | ||
throw error; | ||
} | ||
function newFetch() { | ||
return fetch.apply(this, arguments).then(onResponse); | ||
} | ||
module.exports = newFetch; | ||
// So fetch stays consistent through the whole project | ||
module.exports.replaceGlobal = () => { | ||
module.exports.replaceGlobal = function() { | ||
if (typeof global !== 'undefined') { | ||
@@ -13,0 +23,0 @@ global.fetch = newFetch; |
{ | ||
"name": "isomorphic-fetch-reject", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Isomorphic fetch that rejects on HTTP error", | ||
@@ -10,10 +10,7 @@ "repository": "guestlinelabs/isomorphic-fetch-reject", | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"files": ["index.js"], | ||
"dependencies": { | ||
"es6-promise": "^4.2.4", | ||
"fetch-reject": "^1.3.0", | ||
"isomorphic-fetch": "^2.2.1" | ||
} | ||
} |
# isomorphic-fetch-reject | ||
This package is a mix of [isomorphic-fetch](https://www.npmjs.com/package/isomorphic-fetch) and [fetch-reject](https://www.npmjs.com/package/fetch-reject). It's isomorphic fetch request that rejects also on HTTP error. | ||
This package is using [isomorphic-fetch](https://www.npmjs.com/package/isomorphic-fetch) and extends it to reject on HTTP error. | ||
> Standard fetch does not throw on HTTP errors (non-200 status code). This wrapper allows it to do so. | ||
> 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 the server side as well as on the client side. | ||
This package is perfect for apps that render on both the server and the client side. | ||
@@ -9,0 +9,0 @@ ## Install |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2
23
3186
- Removedfetch-reject@^1.3.0
- Removedfetch-reject@1.3.0(transitive)