fetch-enhance
v0.1.1
Published
A fetch wrapper which knows to reject on bad response status.
Downloads
19
Readme
fetch-enhance
It throws when the response status code is not ok (200~299).
Install
You can use the CDN version or npm package:
$ npm install --save fetch-enhance
Usage
In Browser
fetchEnhance('/url').catch(err => {
// err.status is beyond 200 and 299
// if it's 404
console.log(err.message)
// 'Not Found'
// same as window.fetch 's response data
// eg: data.json() data.text() ...
console.log(err.data)
})
In Node.js
const fetch = require('node-fetch')
const fetchEnhance = require('fetch-enhance')(fetch)
fetchEnhance('/url').catch(/* ... */)
API
fetchEnhance(...options)
Used in browser environment, the same as the options in window.fetch
.
fetchEnhance(fetchImplementation)
Used in Node.js environment, returns a function using the provided fetch implementation, for example: const fetchImplementation = require('node-fetch')
Contributing
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D