Git commit 37ee340bf8bbb686ddeea7dc5233ab30c4cacc1c by Wolfgang Rohdewald. Committed on 31/10/2013 at 21:09. Pushed by wrohdewald into branch 'sid'. better error handling for server login failures M +2 -2 src/humanclient.py M +15 -1 src/login.py http://commits.kde.org/kajongg/37ee340bf8bbb686ddeea7dc5233ab30c4cacc1c diff --git a/src/humanclient.py b/src/humanclient.py index 914bbcd..e21af5b 100644 --- a/src/humanclient.py +++ b/src/humanclient.py @@ -23,6 +23,7 @@ import csv, resource, random from twisted.spread import pb from twisted.python.failure import Failure from twisted.internet.defer import Deferred, succeed, DeferredList, Cancel= ledError +from twisted.internet.error import ConnectionRefusedError, TimeoutError from PyQt4.QtCore import Qt, QTimer from PyQt4.QtGui import QDialog, QVBoxLayout, QGridLayout, \ QLabel, QPushButton, \ @@ -415,10 +416,9 @@ class HumanClient(Client): @staticmethod def __loginFailed(result): """as the name says""" + result.trap(CancelledError, TimeoutError, ConnectionRefusedError) if Internal.field: Internal.field.startingGame =3D False - if result is not CancelledError: - logException(result) = def isRobotClient(self): """avoid using isinstance, it would import too much for kajonggser= ver""" diff --git a/src/login.py b/src/login.py index 6c01c40..dbfa5d2 100644 --- a/src/login.py +++ b/src/login.py @@ -24,6 +24,7 @@ import re from twisted.spread import pb from twisted.cred import credentials from twisted.internet.defer import CancelledError +from twisted.internet.error import ConnectionRefusedError, TimeoutError, C= onnectionLost, DNSLookupError from twisted.python.failure import Failure = from PyQt4.QtGui import QDialog, QDialogButtonBox, QVBoxLayout, \ @@ -504,7 +505,8 @@ class Connection(object): if result: return self.__adduser() else: - return Failure(CancelledError) +# logDebug('loginFailed raises CancelledError') + return Failure(CancelledError()) message =3D failure.getErrorMessage() if 'Wrong username' in message: if self.dlg.host =3D=3D Query.localServerName: @@ -519,6 +521,18 @@ class Connection(object): def _loginReallyFailed(self, failure): """login failed, not fixable by adding missing user""" msg =3D self._prettifyErrorMessage(failure) + if isinstance(failure.value, TimeoutError): + msg =3D m18n('Server %1 did not answer', self.url) + elif isinstance(failure.value, ConnectionRefusedError): + msg =3D m18n('Server %1 refused connection', self.url) + elif isinstance(failure.value, ConnectionLost): + msg =3D m18n('Server %1 does not run a kajongg server' , self.= url) + elif isinstance(failure.value, DNSLookupError): + msg =3D m18n('Server %1 does not run a kajongg server' , self.= url) + else: + msg =3D 'connectino.loginReallyF:%s' % msg +# if 'timeout' in msg: # failure.check(TimeoutError): +# logError(m18n('Server %1 did not answer', self.url)) if failure.check(CancelledError): # show no warning, just leave return failure