Skip to content
Snippets Groups Projects
Commit 987a1a3f authored by inso's avatar inso
Browse files

Catching RequestsExceptions

parent d7f03fb0
No related branches found
No related tags found
No related merge requests found
...@@ -12,7 +12,7 @@ from ..tools.exceptions import NoPeerAvailable ...@@ -12,7 +12,7 @@ from ..tools.exceptions import NoPeerAvailable
import logging import logging
import inspect import inspect
import hashlib import hashlib
from requests.exceptions import ConnectTimeout from requests.exceptions import RequestException, ConnectTimeout
class Cache(): class Cache():
...@@ -128,12 +128,12 @@ class Community(object): ...@@ -128,12 +128,12 @@ class Community(object):
(next_peer.pubkey not in traversed_pubkeys))) (next_peer.pubkey not in traversed_pubkeys)))
if next_peer.pubkey not in traversed_pubkeys: if next_peer.pubkey not in traversed_pubkeys:
self._peering_traversal(next_peer, found_peers, traversed_pubkeys) self._peering_traversal(next_peer, found_peers, traversed_pubkeys)
except ConnectTimeout:
pass
except TimeoutError: except TimeoutError:
pass pass
except ValueError: except ValueError:
pass pass
except RequestException as e:
pass
def peering(self): def peering(self):
peers = [] peers = []
...@@ -218,7 +218,6 @@ class Community(object): ...@@ -218,7 +218,6 @@ class Community(object):
self.peers.remove(peer) self.peers.remove(peer)
self.peers.append(peer) self.peers.append(peer)
continue continue
raise NoPeerAvailable(self.currency, len(self.peers)) raise NoPeerAvailable(self.currency, len(self.peers))
def post(self, request, req_args={}, post_args={}): def post(self, request, req_args={}, post_args={}):
......
...@@ -6,9 +6,10 @@ Created on 2 févr. 2014 ...@@ -6,9 +6,10 @@ Created on 2 févr. 2014
import logging import logging
import time import time
import requests
from ucoinpy.api import bma from ucoinpy.api import bma
from PyQt5.QtWidgets import QWidget, QMenu, QAction, QApplication from PyQt5.QtWidgets import QWidget, QMenu, QAction, QApplication, QMessageBox
from PyQt5.QtCore import QModelIndex, Qt, pyqtSlot, QObject, QThread, pyqtSignal from PyQt5.QtCore import QModelIndex, Qt, pyqtSlot, QObject, QThread, pyqtSignal
from PyQt5.QtGui import QIcon from PyQt5.QtGui import QIcon
from ..gen_resources.currency_tab_uic import Ui_CurrencyTabWidget from ..gen_resources.currency_tab_uic import Ui_CurrencyTabWidget
...@@ -47,6 +48,10 @@ class BlockchainWatcher(QObject): ...@@ -47,6 +48,10 @@ class BlockchainWatcher(QObject):
self.last_block = block_number self.last_block = block_number
except NoPeerAvailable: except NoPeerAvailable:
return return
except requests.exceptions.RequestException as e:
QMessageBox.critical(self, ":(",
str(e),
QMessageBox.Ok)
new_block_mined = pyqtSignal(int) new_block_mined = pyqtSignal(int)
......
...@@ -18,6 +18,7 @@ from ..tools.exceptions import NoPeerAvailable ...@@ -18,6 +18,7 @@ from ..tools.exceptions import NoPeerAvailable
from ..__init__ import __version__ from ..__init__ import __version__
import logging import logging
import requests
class Loader(QObject): class Loader(QObject):
...@@ -189,6 +190,10 @@ class MainWindow(QMainWindow, Ui_MainWindow): ...@@ -189,6 +190,10 @@ class MainWindow(QMainWindow, Ui_MainWindow):
str(e), str(e),
QMessageBox.Ok) QMessageBox.Ok)
continue continue
except requests.exceptions.RequestException as e:
QMessageBox.critical(self, ":(",
str(e),
QMessageBox.Ok)
self.menu_contacts_list.clear() self.menu_contacts_list.clear()
for contact in self.app.current_account.contacts: for contact in self.app.current_account.contacts:
......
...@@ -5,6 +5,8 @@ Created on 8 mars 2014 ...@@ -5,6 +5,8 @@ Created on 8 mars 2014
''' '''
import logging import logging
import requests
from ucoinpy.api import bma from ucoinpy.api import bma
from ucoinpy.api.bma import ConnectionHandler from ucoinpy.api.bma import ConnectionHandler
from ucoinpy.documents.peer import Peer from ucoinpy.documents.peer import Peer
...@@ -65,6 +67,11 @@ class StepPageInit(Step): ...@@ -65,6 +67,11 @@ class StepPageInit(Step):
QMessageBox.critical(self.config_dialog, "Server Error", QMessageBox.critical(self.config_dialog, "Server Error",
"Cannot join any peer in this community.") "Cannot join any peer in this community.")
raise raise
except requests.exceptions.RequestException as e:
QMessageBox.critical(self, ":(",
str(e),
QMessageBox.Ok)
raise
def display_page(self): def display_page(self):
self.config_dialog.button_previous.setEnabled(False) self.config_dialog.button_previous.setEnabled(False)
...@@ -155,8 +162,12 @@ class ProcessConfigureCommunity(QDialog, Ui_CommunityConfigurationDialog): ...@@ -155,8 +162,12 @@ class ProcessConfigureCommunity(QDialog, Ui_CommunityConfigurationDialog):
peer = Peer.from_signed_raw("{0}{1}\n".format(peer_data['raw'], peer = Peer.from_signed_raw("{0}{1}\n".format(peer_data['raw'],
peer_data['signature'])) peer_data['signature']))
if peer.currency == self.community.currency:
self.community.peers.append(peer) self.community.peers.append(peer)
except: else:
QMessageBox.critical(self, "Error",
"This peer doesn't use this community currency.")
except requests.exceptions.RequestException as e:
QMessageBox.critical(self, "Server error", QMessageBox.critical(self, "Server error",
"Cannot get node peering") "Cannot get node peering")
self.tree_peers.setModel(PeeringTreeModel(self.community)) self.tree_peers.setModel(PeeringTreeModel(self.community))
...@@ -187,6 +198,15 @@ Would you like to publish the key ?""".format(self.account.pubkey)) ...@@ -187,6 +198,15 @@ Would you like to publish the key ?""".format(self.account.pubkey))
except ValueError as e: except ValueError as e:
QMessageBox.critical(self, "Pubkey publishing error", QMessageBox.critical(self, "Pubkey publishing error",
e.message) e.message)
except NoPeerAvailable as e:
QMessageBox.critical(self, "Network error",
"Couldn't connect to network : {0}".format(e),
QMessageBox.Ok)
except Exception as e:
QMessageBox.critical(self, "Error",
"{0}".format(e),
QMessageBox.Ok)
else: else:
return return
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment