It throws when the response status code is not ok (200~299).
You can use the CDN version or npm package:
$ npm install --save fetch-enhance
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)
})
const fetch = require('node-fetch')
const fetchEnhance = require('fetch-enhance')(fetch)
fetchEnhance('/url').catch(/* ... */)
Used in browser environment, the same as the options in window.fetch
.
Used in Node.js environment, returns a function using the provided fetch implementation, for example: const fetchImplementation = require('node-fetch')
- 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