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):
return _('No more available requests on %s') % (self.name)
pass
class NetworkDNSError(NetworkError):
@ -85,7 +84,6 @@ class NetworkDNSError(NetworkError):
def __str__(self):
return _('DNS failure on a request to %s') % (self.name)
pass
class NetworkInvalidResponseError(NetworkError):
@ -97,7 +95,6 @@ class NetworkInvalidResponseError(NetworkError):
def __str__(self):
return _('The server on %s returned the information in an ' \
'unexpected way.') % (self.name)
pass
class NetworkLowLevelError(NetworkError):
@ -109,7 +106,6 @@ class NetworkLowLevelError(NetworkError):
def __str__(self):
return _('Low level error in the network layer when talking ' \
'to %s') % (self.name)
pass
class NetworkBadStatusLineError(NetworkError):
@ -119,7 +115,6 @@ class NetworkBadStatusLineError(NetworkError):
def __str__(self):
return _('Bad status line in network %s') % (self.name)
pass
class NetworkAuthorizationFailError(NetworkError):
@ -129,7 +124,6 @@ class NetworkAuthorizationFailError(NetworkError):
def __str__(self):
return _('Autorization failed for %s') % (self.name)
pass
class NetworkPermissionDeniedError(NetworkError):
@ -139,7 +133,16 @@ class NetworkPermissionDeniedError(NetworkError):
def __str__(self):
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
@ -157,7 +160,6 @@ class MessageTooLongWarning(NetworkWarning):
def __str__(self):
return _('Message too long for %s') % (self.name)
pass
#--------------------------------------------------------------------
# The classes

14
mitterlib/network/twitter.py

@ -277,14 +277,22 @@ class Connection(NetworkBase):
data = response.read()
except urllib2.HTTPError, exc:
body = exc.read()
_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
# "Something is technically wrong" most of the time in the real
# pages.
if exc.code == 403:
# Permission denied.
raise NetworkPermissionDeniedError(self.NAMESPACE)
# 403 can be either permission denied or a complain that the
# 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)
except urllib2.URLError, exc:
_log.error('URL error: %s' % exc.reason)

Loading…
Cancel
Save