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
|
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)
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue