From c4e73ddd922cc87a9f528a904ed2725ba96ba347 Mon Sep 17 00:00:00 2001 From: Aymen Mouelhi Date: Sun, 5 Mar 2017 18:53:20 -0800 Subject: [PATCH] Fix Issue with network errors Summary: When running the Movies Example, the application displays an error message: "Cannot read property 'total' of undefined". capture d ecran 2017-03-01 a 21 26 50 This is due to the fact that the API call raised an error, and the catch block is followed by a then block, which means that the code in the second then bloc will be executed. The fix is to move the catch at the last position, to prevent any further execution in case of network error. Closes https://github.com/facebook/react-native/pull/12641 Differential Revision: D4657739 Pulled By: ericvicenti fbshipit-source-id: bdc58d2b89a7d2a53de716773e7bc8a735fa2e45 --- Examples/Movies/SearchScreen.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Examples/Movies/SearchScreen.js b/Examples/Movies/SearchScreen.js index 316b974e5..57fa82885 100644 --- a/Examples/Movies/SearchScreen.js +++ b/Examples/Movies/SearchScreen.js @@ -123,15 +123,6 @@ var SearchScreen = React.createClass({ fetch(this._urlForQueryAndPage(query, 1)) .then((response) => response.json()) - .catch((error) => { - LOADING[query] = false; - resultsCache.dataForQuery[query] = undefined; - - this.setState({ - dataSource: this.getDataSource([]), - isLoading: false, - }); - }) .then((responseData) => { LOADING[query] = false; resultsCache.totalForQuery[query] = responseData.total; @@ -148,6 +139,15 @@ var SearchScreen = React.createClass({ dataSource: this.getDataSource(responseData.movies), }); }) + .catch((error) => { + LOADING[query] = false; + resultsCache.dataForQuery[query] = undefined; + + this.setState({ + dataSource: this.getDataSource([]), + isLoading: false, + }); + }) .done(); },