diff --git a/src/pages/index.js b/src/pages/index.js index a69a2bc..64ca885 100644 --- a/src/pages/index.js +++ b/src/pages/index.js @@ -65,9 +65,7 @@ class IndexPage extends Component { this.setLoading(true); - return callApi(body).then(response => { - console.log(response); - + return (this.callApi = () => { // API response // { // "id": "7f8f07f3-41a6-4aa3-8b6e-c456766d0e70", @@ -88,9 +86,17 @@ class IndexPage extends Component { // "content_type": "m" // } - this.state._Recommendation.addContent(response); - this.setLoading(false); - }); + return callApi(body).then(response => { + if (Object.keys(response).length <= 0) { + console.log("retrying..."); + return this.callApi(); + } else { + console.log("success:", response); + this.state._Recommendation.addContent(response); + this.setLoading(false); + } + }); + })(); } handleChange(event) { @@ -115,7 +121,7 @@ class IndexPage extends Component {