Silently fail in share worker if user account is suspended

This commit is contained in:
Andreas Nedbal 2022-12-27 17:53:02 +01:00 committed by Andreas Nedbal
parent 712328bd86
commit 37f4b78f66
2 changed files with 11 additions and 0 deletions

View File

@ -18,6 +18,10 @@ class ShareWorker
rescue Twitter::Error::DuplicateStatus rescue Twitter::Error::DuplicateStatus
logger.info "Tried to post answer ##{answer_id} from user ##{user_id} to Twitter but the status was already posted." logger.info "Tried to post answer ##{answer_id} from user ##{user_id} to Twitter but the status was already posted."
return 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 rescue Twitter::Error::Unauthorized
# User's Twitter token has expired or been revoked # User's Twitter token has expired or been revoked
# TODO: Notify user if this happens (https://github.com/Retrospring/retrospring/issues/123) # TODO: Notify user if this happens (https://github.com/Retrospring/retrospring/issues/123)

View File

@ -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.") 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 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 it "retries on unhandled exceptions" do
expect { subject }.to change(ShareWorker.jobs, :size).by(1) expect { subject }.to change(ShareWorker.jobs, :size).by(1)
expect { ShareWorker.drain }.to raise_error(Twitter::Error::BadRequest) expect { ShareWorker.drain }.to raise_error(Twitter::Error::BadRequest)