Silently fail in share worker if user account is suspended
This commit is contained in:
parent
712328bd86
commit
37f4b78f66
|
@ -18,6 +18,10 @@ class ShareWorker
|
|||
rescue Twitter::Error::DuplicateStatus
|
||||
logger.info "Tried to post answer ##{answer_id} from user ##{user_id} to Twitter but the status was already posted."
|
||||
return
|
||||
rescue Twitter::Error::Forbidden
|
||||
# User's Twitter account is suspended
|
||||
logger.info "Tried to post answer ##{answer_id} from user ##{user_id} to Twitter but the account is suspended."
|
||||
return
|
||||
rescue Twitter::Error::Unauthorized
|
||||
# User's Twitter token has expired or been revoked
|
||||
# TODO: Notify user if this happens (https://github.com/Retrospring/retrospring/issues/123)
|
||||
|
|
|
@ -59,6 +59,13 @@ describe ShareWorker do
|
|||
expect(Sidekiq.logger).to have_received(:info).with("Tried to post answer ##{answer.id} from user ##{user.id} to Twitter but the token has exired or been revoked.")
|
||||
end
|
||||
|
||||
it "handles Twitter::Error::Forbidden" do
|
||||
allow_any_instance_of(Services::Twitter).to receive(:post).with(answer).and_raise(Twitter::Error::Forbidden)
|
||||
subject
|
||||
ShareWorker.drain
|
||||
expect(Sidekiq.logger).to have_received(:info).with("Tried to post answer ##{answer.id} from user ##{user.id} to Twitter but the account is suspended.")
|
||||
end
|
||||
|
||||
it "retries on unhandled exceptions" do
|
||||
expect { subject }.to change(ShareWorker.jobs, :size).by(1)
|
||||
expect { ShareWorker.drain }.to raise_error(Twitter::Error::BadRequest)
|
||||
|
|
Loading…
Reference in New Issue