From 682a2aea1cdc89fd1432490d0b6e55b103322a4b Mon Sep 17 00:00:00 2001 From: Muhsin Keloth Date: Mon, 22 Jan 2024 17:03:26 +0530 Subject: [PATCH] chore: Handle twillio `Down::ClientError` (#8757) Fixes: https://linear.app/chatwoot/issue/CW-2992/downclienterror-400-bad-request-downclienterror --- app/services/twilio/incoming_message_service.rb | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/app/services/twilio/incoming_message_service.rb b/app/services/twilio/incoming_message_service.rb index f28192f4e..e379b6e0d 100644 --- a/app/services/twilio/incoming_message_service.rb +++ b/app/services/twilio/incoming_message_service.rb @@ -127,7 +127,7 @@ class Twilio::IncomingMessageService def download_attachment_file download_with_auth - rescue Down::Error => e + rescue Down::Error, Down::ClientError => e handle_download_attachment_error(e) end @@ -141,12 +141,10 @@ class Twilio::IncomingMessageService # This is just a temporary workaround since some users have not yet enabled media protection. We will remove this in the future. def handle_download_attachment_error(error) - Rails.logger.info "Error downloading attachment from Twilio: #{error.message}" - if error.message.include?('401 Unauthorized') - Down.download(params[:MediaUrl0]) - else - ChatwootExceptionTracker.new(error, account: @inbox.account).capture_exception - nil - end + Rails.logger.info "Error downloading attachment from Twilio: #{error.message}: Retrying" + Down.download(params[:MediaUrl0]) + rescue StandardError => e + Rails.logger.info "Error downloading attachment from Twilio: #{e.message}: Skipping" + nil end end