Skip to content

Commit

Permalink
Merge pull request #128 from michielbdejong/http-error-detection
Browse files Browse the repository at this point in the history
Hint at http error reporting in docs example, fix #124
  • Loading branch information
n1k0 committed Aug 26, 2015
2 parents c5f55f0 + d52ac16 commit 47fee00
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,21 @@ Synopsis:
```js
articles.sync()
.then(console.log.bind(console))
.catch(console.error.bind(console));
.catch(err => {
if (err.response && err.response.status === 401) {
console.error('HTTP status code indicates auth problem');
}
});
```

### Error handling

If anything goes wrong during sync, `colllection.sync()` will reject its promise with an `error` object, as follows:
* If an unexpected HTTP status is received from the server, `error.response` will contain that response, for you to inspect
(see the example above for detecting 401 Unauthorized errors).
* If the server is unreachable, `error.response` will be undefined, but `error.message` will equal
`'HTTP 0; TypeError: NetworkError when attempting to fetch resource.'`.

### Synchronization strategies

The `sync()` method accepts a `strategy` option, which itself accepts the following values:
Expand Down

0 comments on commit 47fee00

Please sign in to comment.