From 8d2ab6f38e7492949c83f0beef832590549b6c1b Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Mon, 8 Jul 2019 09:30:24 -0700 Subject: [PATCH] fix: catch Mixed Content failures that take down the app --- src/App.js | 19 +++++++++++++------ src/AppV2.js | 6 +++++- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/App.js b/src/App.js index 662ad325..a09d03a3 100755 --- a/src/App.js +++ b/src/App.js @@ -77,10 +77,10 @@ class App extends Component { { enabled: true, dialogOpen: false, - ws: null, }, this.defaultState, ); + this.ws = null; setInterval(() => { this.updateTxnStats(); @@ -90,8 +90,9 @@ class App extends Component { }, 10000); } - getRemoteState(attr, url, mapFun, limit, transform) { - axios.get(url).then(response => { + async getRemoteState(attr, url, mapFun, limit, transform) { + try { + const response = await axios.get(url); let newState = {}; if (limit) { @@ -109,7 +110,9 @@ class App extends Component { } this.updateStateAttributes(newState); - }); + } catch (err) { + console.error('getRemoteState failed:', err); + } } updateSpecificGlobalStateAttribute(attr, value) { @@ -250,7 +253,7 @@ class App extends Component { }; onEndpointChange() { - if (this.ws) { + if (this.ws !== null) { this.ws.close(); this.ws = null; } @@ -285,7 +288,11 @@ class App extends Component { } componentDidMount() { - this.onEndpointChange(); + try { + this.onEndpointChange(); + } catch (err) { + console.error('onEndpointChange failed:', err); + } if (!this.locationListener) { const locationListener = this.handleLocationChange(); diff --git a/src/AppV2.js b/src/AppV2.js index 6c00bb63..fef4402b 100644 --- a/src/AppV2.js +++ b/src/AppV2.js @@ -9,7 +9,11 @@ import Footer from 'v2/components/Footer'; import theme from 'v2/theme'; import socket from 'v2/stores/socket'; -socket.init(); +try { + socket.init(); +} catch (err) { + console.error('Socket init failed:', err); +} const Dashboard = lazy(() => import('v2/components/Dashboard'));