improve message "error 111" if connection failed

Raise OfflineImapError with severity REPO explaining that the connection failed.
Before, no valuable information was given to the user.

Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
Nicolas Sebrecht 2011-05-24 23:45:39 +02:00
parent da36c5c1e7
commit fc6c12d96c
2 changed files with 11 additions and 4 deletions

View File

@ -172,8 +172,8 @@ class WrappedIMAP4_SSL(UsefulIMAPMixIn, IMAP4_SSL):
else:
self.sock.close()
if last_error != 0:
# FIXME
raise socket.error(last_error)
raise Exception("can't open socket; error: %s"\
% socket.error(last_error))
# Allow sending of keep-alive message seems to prevent some servers
# from closing SSL on us leading to deadlocks
@ -276,8 +276,8 @@ class WrappedIMAP4(UsefulIMAPMixIn, IMAP4):
else:
self.sock.close()
if last_error != 0:
# FIXME
raise socket.error(last_error)
raise Exception("can't open socket; error: %s"\
% socket.error(last_error))
self.file = self.sock.makefile('rb')
# imaplib2 uses this to poll()

View File

@ -289,6 +289,13 @@ class IMAPServer:
"ver name correctly and that you are online."\
% (self.hostname, self.reposname)
raise OfflineImapError(reason, severity)
# Could not acquire connection to the remote;
# socket.error(last_error) raised
if str(e)[:24] == "can't open socket; error":
raise OfflineImapError("Could not connect to remote server '%s' "\
"for repository '%s'. Remote does not answer."
% (self.hostname, self.reposname),
OfflineImapError.ERROR.REPO)
else:
# re-raise all other errors
raise