From ebbda0ca5f4bdf5b7e2ffb59623a0e4ccd45b5a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Le=20Gall?= Date: Wed, 11 Apr 2018 16:36:47 +0200 Subject: [PATCH] Doc : Add errors from API handling examples Fix #582 --- docs/media/api_guide.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docs/media/api_guide.md b/docs/media/api_guide.md index 86b2655347d..0a5cc076d51 100644 --- a/docs/media/api_guide.md +++ b/docs/media/api_guide.md @@ -112,6 +112,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 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 @@ -123,6 +126,8 @@ let myInit = { // OPTIONAL } API.get(apiName, path, myInit).then(response => { // Add your code here +}).catch(error => { + console.log(error.response) }); ``` @@ -156,6 +161,8 @@ let myInit = { API.post(apiName, path, myInit).then(response => { // Add your code here +}).catch(error => { + console.log(error.response) }); ``` @@ -187,6 +194,8 @@ let myInit = { API.put(apiName, path, myInit).then(response => { // Add your code here +}).catch(error => { + console.log(error.response) }); ``` @@ -217,6 +226,8 @@ let myInit = { // OPTIONAL API.del(apiName, path, myInit).then(response => { // Add your code here +}).catch(error => { + console.log(error.response) }); ```