[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kajongg/sid] src: better error handling for server login failures
From:       Wolfgang Rohdewald <wolfgang () rohdewald ! de>
Date:       2013-10-31 21:21:15
Message-ID: E1Vbzg3-0002lj-0b () scm ! kde ! org
[Download RAW message or body]

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, CancelledError
+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 = False
-        if result is not CancelledError:
-            logException(result)
 
     def isRobotClient(self):
         """avoid using isinstance, it would import too much for kajonggserver"""
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, ConnectionLost, 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 = failure.getErrorMessage()
         if 'Wrong username' in message:
             if self.dlg.host == Query.localServerName:
@@ -519,6 +521,18 @@ class Connection(object):
     def _loginReallyFailed(self, failure):
         """login failed, not fixable by adding missing user"""
         msg = self._prettifyErrorMessage(failure)
+        if isinstance(failure.value, TimeoutError):
+            msg = m18n('Server %1 did not answer', self.url)
+        elif isinstance(failure.value, ConnectionRefusedError):
+            msg = m18n('Server %1 refused connection', self.url)
+        elif isinstance(failure.value, ConnectionLost):
+            msg = m18n('Server %1 does not run a kajongg server' , self.url)
+        elif isinstance(failure.value, DNSLookupError):
+            msg = m18n('Server %1 does not run a kajongg server' , self.url)
+        else:
+            msg = '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

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic