Skip to content

Commit

Permalink
Log twitter api failures in twitter transport
Browse files Browse the repository at this point in the history
  • Loading branch information
justinvdm committed Apr 1, 2014
1 parent f295327 commit 5f6cef0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
22 changes: 16 additions & 6 deletions vumi/transports/twitter/tests/test_twitter.py
Expand Up @@ -342,10 +342,15 @@ def fail(*a, **kw):

self.patch(self.client, 'statuses_update', fail)

msg = yield self.tx_helper.make_dispatch_outbound(
'hello', endpoint='tweet_endpoint')
[nack] = yield self.tx_helper.wait_for_dispatched_events(1)
with LogCatcher() as lc:
msg = yield self.tx_helper.make_dispatch_outbound(
'hello', endpoint='tweet_endpoint')

self.assertEqual(
[e['message'][0] for e in lc.errors],
["'Outbound twitter message failed: :('"])

[nack] = yield self.tx_helper.wait_for_dispatched_events(1)
self.assertEqual(nack['user_message_id'], msg['message_id'])
self.assertEqual(nack['sent_message_id'], msg['message_id'])
self.assertEqual(nack['nack_reason'], ':(')
Expand Down Expand Up @@ -375,10 +380,15 @@ def fail(*a, **kw):

self.patch(self.client, 'direct_messages_new', fail)

msg = yield self.tx_helper.make_dispatch_outbound(
'hello', endpoint='dm_endpoint')
[nack] = yield self.tx_helper.wait_for_dispatched_events(1)
with LogCatcher() as lc:
msg = yield self.tx_helper.make_dispatch_outbound(
'hello', endpoint='dm_endpoint')

self.assertEqual(
[e['message'][0] for e in lc.errors],
["'Outbound twitter message failed: :('"])

[nack] = yield self.tx_helper.wait_for_dispatched_events(1)
self.assertEqual(nack['user_message_id'], msg['message_id'])
self.assertEqual(nack['sent_message_id'], msg['message_id'])
self.assertEqual(nack['nack_reason'], ':(')
Expand Down
5 changes: 4 additions & 1 deletion vumi/transports/twitter/twitter.py
Expand Up @@ -112,10 +112,13 @@ def handler(message):
user_message_id=message['message_id'],
sent_message_id=twitter_message['id_str'])
except Exception, e:
reason = '%s' % (e,)
log.err('Outbound twitter message failed: %s' % (reason,))

yield self.publish_nack(
user_message_id=message['message_id'],
sent_message_id=message['message_id'],
reason='%s' % (e,))
reason=reason)

return handler

Expand Down

0 comments on commit 5f6cef0

Please sign in to comment.