From ea493de2a50c42dd943024f524ffae2572800ba2 Mon Sep 17 00:00:00 2001
From: Inso <insomniak.fr@gmail.com>
Date: Sun, 25 Jan 2015 15:50:29 +0100
Subject: [PATCH] Catching more requests exceptions

---
 src/cutecoin/core/app.py       | 6 +++---
 src/cutecoin/gui/mainwindow.py | 9 +++++++--
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/src/cutecoin/core/app.py b/src/cutecoin/core/app.py
index ec276bae..ae2c1c5e 100644
--- a/src/cutecoin/core/app.py
+++ b/src/cutecoin/core/app.py
@@ -90,9 +90,9 @@ class Application(object):
             wallet_path = os.path.join(config.parameters['home'],
                                         account.name, '__cache__', wallet.pubkey)
             if os.path.exists(wallet_path):
-                json_data = open(wallet_path, 'r')
-                data = json.load(json_data)
-                wallet.load_caches(data)
+                with open(wallet_path, 'r') as json_data:
+                    data = json.load(json_data)
+                    wallet.load_caches(data)
             for community in account.communities:
                 wallet.refresh_cache(community)
 
diff --git a/src/cutecoin/gui/mainwindow.py b/src/cutecoin/gui/mainwindow.py
index 4a8f05d5..f205d4cd 100644
--- a/src/cutecoin/gui/mainwindow.py
+++ b/src/cutecoin/gui/mainwindow.py
@@ -35,7 +35,12 @@ class Loader(QObject):
     @pyqtSlot()
     def load(self):
         if self.account_name != "":
-            self.app.change_current_account(self.app.get_account(self.account_name))
+            try:
+                self.app.change_current_account(self.app.get_account(self.account_name))
+            except requests.exceptions.RequestException as e:
+                QMessageBox.critical(self, ":(",
+                            str(e),
+                            QMessageBox.Ok)
         self.loaded.emit()
 
 
@@ -163,7 +168,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
         else:
             for dead in self.app.current_account.dead_communities:
                 QMessageBox.critical(self, ":(",
-                            "No {0} peers could be joined. Community was lost.".format(dead),
+                            "No {0} peers could be joined. Connection to its network is lost.".format(dead),
                             QMessageBox.Ok)
 
             self.action_set_as_default.setEnabled(self.app.current_account.name
-- 
GitLab