Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 13 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
For use with [node](http://nodejs.org) and [npm](https://npmjs.com):

```sh
npm install --save unfetch
npm i unfetch
```

Otherwise, grab it from [unpkg.com/unfetch](https://unpkg.com/unfetch/).
Expand Down Expand Up @@ -85,7 +85,7 @@ you can import unfetch to use in your code without modifying any globals:
import fetch from 'unfetch'

// or using CommonJS:
var fetch = require('unfetch')
const fetch = require('unfetch')

// usage:
fetch('/foo.json')
Expand Down Expand Up @@ -193,21 +193,19 @@ fetch('/users', {

```javascript
fetch('/users')
.then( checkStatus )
.then( r => r.json() )
.then( data => {
console.log(data);
});

function checkStatus(response) {
if (response.ok) {
return response;
} else {
var error = new Error(response.statusText);
.then(response => {
if (response.ok) {
return response;
}
// convert non-2xx HTTP responses into errors:
const error = new Error(response.statusText);
error.response = response;
return Promise.reject(error);
}
}
})
.then(response => response.json())
.then(data => {
console.log(data);
});
```

* * *
Expand Down