[bug 951702] Handle IOErrors in twitter middleware

Pretty sure this doesn't affect users, but it is a source of errors in
Sentry and it's easy to fix.

In order to fix it, I had to tweak the structure of the code from one big
if-statement into smaller blocks that exit out when they're done.