Browse Source

test for duplicate error

master
Julio Biason 15 years ago
parent
commit
8e366de68f
  1. 18
      mitterlib/network/networkbase.py
  2. 14
      mitterlib/network/twitter.py

18
mitterlib/network/networkbase.py

@ -74,7 +74,6 @@ class NetworkLimitExceededError(NetworkError):
def __str__(self): def __str__(self):
return _('No more available requests on %s') % (self.name) return _('No more available requests on %s') % (self.name)
pass
class NetworkDNSError(NetworkError): class NetworkDNSError(NetworkError):
@ -85,7 +84,6 @@ class NetworkDNSError(NetworkError):
def __str__(self): def __str__(self):
return _('DNS failure on a request to %s') % (self.name) return _('DNS failure on a request to %s') % (self.name)
pass
class NetworkInvalidResponseError(NetworkError): class NetworkInvalidResponseError(NetworkError):
@ -97,7 +95,6 @@ class NetworkInvalidResponseError(NetworkError):
def __str__(self): def __str__(self):
return _('The server on %s returned the information in an ' \ return _('The server on %s returned the information in an ' \
'unexpected way.') % (self.name) 'unexpected way.') % (self.name)
pass
class NetworkLowLevelError(NetworkError): class NetworkLowLevelError(NetworkError):
@ -109,7 +106,6 @@ class NetworkLowLevelError(NetworkError):
def __str__(self): def __str__(self):
return _('Low level error in the network layer when talking ' \ return _('Low level error in the network layer when talking ' \
'to %s') % (self.name) 'to %s') % (self.name)
pass
class NetworkBadStatusLineError(NetworkError): class NetworkBadStatusLineError(NetworkError):
@ -119,7 +115,6 @@ class NetworkBadStatusLineError(NetworkError):
def __str__(self): def __str__(self):
return _('Bad status line in network %s') % (self.name) return _('Bad status line in network %s') % (self.name)
pass
class NetworkAuthorizationFailError(NetworkError): class NetworkAuthorizationFailError(NetworkError):
@ -129,7 +124,6 @@ class NetworkAuthorizationFailError(NetworkError):
def __str__(self): def __str__(self):
return _('Autorization failed for %s') % (self.name) return _('Autorization failed for %s') % (self.name)
pass
class NetworkPermissionDeniedError(NetworkError): class NetworkPermissionDeniedError(NetworkError):
@ -139,7 +133,16 @@ class NetworkPermissionDeniedError(NetworkError):
def __str__(self): def __str__(self):
return _('Permission denied received on %s') % (self.name) return _('Permission denied received on %s') % (self.name)
pass
class NetworkMessageDuplicatedError(NetworkError):
"""Network pointed that the message is duplicated."""
def __init__(self, network_name):
self.name = network_name
def __str__(self):
return _('%s refused the message due being duplicated') % (self.name)
#-------------------------------------------------------------------- #--------------------------------------------------------------------
# Warnings # Warnings
@ -157,7 +160,6 @@ class MessageTooLongWarning(NetworkWarning):
def __str__(self): def __str__(self):
return _('Message too long for %s') % (self.name) return _('Message too long for %s') % (self.name)
pass
#-------------------------------------------------------------------- #--------------------------------------------------------------------
# The classes # The classes

14
mitterlib/network/twitter.py

@ -277,14 +277,22 @@ class Connection(NetworkBase):
data = response.read() data = response.read()
except urllib2.HTTPError, exc: except urllib2.HTTPError, exc:
body = exc.read()
_log.debug('HTTPError: %d' % (exc.code)) _log.debug('HTTPError: %d' % (exc.code))
_log.debug('HTTPError: response body:\n%s' % exc.read()) _log.debug('HTTPError: response body:\n%s' % (body))
# To me, I got a lot of 502 for "replies". It shows the # To me, I got a lot of 502 for "replies". It shows the
# "Something is technically wrong" most of the time in the real # "Something is technically wrong" most of the time in the real
# pages. # pages.
if exc.code == 403: if exc.code == 403:
# Permission denied. # 403 can be either permission denied or a complain that the
raise NetworkPermissionDeniedError(self.NAMESPACE) # update is duplicated.
if 'duplicate.' in body:
# yes, this is a very week testing. I just don't want to
# mess again with try/except to check the json result.
raise NetworkMessageDuplicatedError(self.NAMESPACE)
else:
# Permission denied.
raise NetworkPermissionDeniedError(self.NAMESPACE)
raise NetworkInvalidResponseError(self.NAMESPACE) raise NetworkInvalidResponseError(self.NAMESPACE)
except urllib2.URLError, exc: except urllib2.URLError, exc:
_log.error('URL error: %s' % exc.reason) _log.error('URL error: %s' % exc.reason)

Loading…
Cancel
Save