From 64042c9de8f24e9c0765236a82cdf045b7edeedb Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 16 Jul 2015 16:12:54 +0100 Subject: [PATCH] Handle localstorage exceptions. --- src/controllers/pages/MatrixChat.js | 6 +++--- src/controllers/templates/Login.js | 13 +++++++++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/controllers/pages/MatrixChat.js b/src/controllers/pages/MatrixChat.js index 872a513117..7c4e35c552 100644 --- a/src/controllers/pages/MatrixChat.js +++ b/src/controllers/pages/MatrixChat.js @@ -72,9 +72,9 @@ module.exports = { logged_in: false, ready: false }); - localStorage.removeItem("mx_hs_url"); - localStorage.removeItem("mx_user_id"); - localStorage.removeItem("mx_access_token"); + if (window.localStorage) { + window.localStorage.clear(); + } Notifier.stop(); MatrixClientPeg.get().removeAllListeners(); MatrixClientPeg.replace(null); diff --git a/src/controllers/templates/Login.js b/src/controllers/templates/Login.js index 1c05597080..2719436ebd 100644 --- a/src/controllers/templates/Login.js +++ b/src/controllers/templates/Login.js @@ -82,10 +82,15 @@ module.exports = { })); var localStorage = window.localStorage; if (localStorage) { - localStorage.setItem("mx_hs_url", that.state.hs_url); - localStorage.setItem("mx_is_url", that.state.is_url); - localStorage.setItem("mx_user_id", data.user_id); - localStorage.setItem("mx_access_token", data.access_token); + try { + localStorage.clear(); + localStorage.setItem("mx_hs_url", that.state.hs_url); + localStorage.setItem("mx_is_url", that.state.is_url); + localStorage.setItem("mx_user_id", data.user_id); + localStorage.setItem("mx_access_token", data.access_token); + } catch (e) { + console.warn("Error using local storage: can't persist session!"); + } } else { console.warn("No local storage available: can't persist session!"); }