Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doc : Add errors from API handling examples #633

Merged
merged 2 commits into from
Apr 19, 2018
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
11 changes: 11 additions & 0 deletions docs/media/api_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ The following code sample assumes you have used Automated Setup.

To invoke an endpoint, you need to set `apiName`, `path` and `headers` parameters, and each method returns a Promise.

Under the hood, aws-amplify use [Axios](https://github.com/axios/axios), so the API status code response > 299 are thrown as an exception.
If you need to handle errors managed by your API, work with the `error.response` object.

#### **GET**

```js
Expand All @@ -125,6 +128,8 @@ let myInit = { // OPTIONAL
}
API.get(apiName, path, myInit).then(response => {
// Add your code here
}).catch(error => {
console.log(error.response)
});
```

Expand Down Expand Up @@ -158,6 +163,8 @@ let myInit = {

API.post(apiName, path, myInit).then(response => {
// Add your code here
}).catch(error => {
console.log(error.response)
});
```

Expand Down Expand Up @@ -189,6 +196,8 @@ let myInit = {

API.put(apiName, path, myInit).then(response => {
// Add your code here
}).catch(error => {
console.log(error.response)
});
```

Expand Down Expand Up @@ -219,6 +228,8 @@ let myInit = { // OPTIONAL

API.del(apiName, path, myInit).then(response => {
// Add your code here
}).catch(error => {
console.log(error.response)
});
```

Expand Down