fix: Handle Twilio::REST::RestError (#8257)

This commit is contained in:
Muhsin Keloth
2023-10-31 16:23:34 +05:30
committed by GitHub
parent 11b27f9805
commit 29f18c7f18
2 changed files with 12 additions and 1 deletions

View File

@@ -8,8 +8,9 @@ class Twilio::SendOnTwilioService < Base::SendOnChannelService
def perform_reply
begin
twilio_message = channel.send_message(**message_params)
rescue Twilio::REST::TwilioError => e
rescue Twilio::REST::TwilioError, Twilio::REST::RestError => e
ChatwootExceptionTracker.new(e, user: message.sender, account: message.account).capture_exception
message.update!(status: :failed, external_error: e.message)
end
message.update!(source_id: twilio_message.sid) if twilio_message
end

View File

@@ -96,5 +96,15 @@ describe Twilio::SendOnTwilioService do
described_class.new(message: message).perform
expect(messages_double).to have_received(:create).with(hash_including(media_url: [anything]))
end
it 'if message is sent from chatwoot fails' do
allow(messages_double).to receive(:create).and_raise(Twilio::REST::TwilioError)
outgoing_message = create(
:message, message_type: 'outgoing', inbox: twilio_inbox, account: account, conversation: conversation
)
described_class.new(message: outgoing_message).perform
expect(outgoing_message.reload.status).to eq('failed')
end
end
end