From 58a5065e5253ed969f88cc68a18a39bb5676e955 Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Mon, 27 Dec 2021 17:44:42 +0100 Subject: [PATCH] Catch common `ShareWorker` exceptions to avoid unnecessary retries --- app/workers/share_worker.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/workers/share_worker.rb b/app/workers/share_worker.rb index 6d6067cf..be70d022 100644 --- a/app/workers/share_worker.rb +++ b/app/workers/share_worker.rb @@ -11,6 +11,15 @@ class ShareWorker user_service = User.find(user_id).services.find_by(type: service_type) user_service.post(Answer.find(answer_id)) + rescue ActiveRecord::RecordNotFound + # The question to be posted was deleted + return + rescue Twitter::Error::DuplicateStatus + 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) + return rescue => e logger.info "failed to post answer #{answer_id} to #{service} for user #{user_id}: #{e.message}" NewRelic::Agent.notice_error(e)