chore: Handle the Twilio exception in sentry

Fix trying to extract the Sid from non created message.

Fixes #3029
This commit is contained in:
Tejaswini Chile 2021-09-21 23:02:45 +05:30 committed by GitHub
parent c504067e2b
commit dddab0bbce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 2 deletions

View file

@ -9,9 +9,9 @@ class Twilio::SendOnTwilioService < Base::SendOnChannelService
begin
twilio_message = client.messages.create(**message_params)
rescue Twilio::REST::TwilioError => e
Rails.logger.info "Twilio Error: #{e.message}"
Sentry.capture_exception(e)
end
message.update!(source_id: twilio_message.sid)
message.update!(source_id: twilio_message.sid) if twilio_message
end
def message_params

View file

@ -28,6 +28,7 @@ describe Twilio::SendOnTwilioService do
message = create(:message, message_type: 'outgoing', private: true, inbox: twilio_inbox, account: account)
::Twilio::SendOnTwilioService.new(message: message).perform
expect(twilio_client).not_to have_received(:messages)
expect(message.reload.source_id).to be_nil
end
it 'if inbox channel is not twilio' do
@ -40,6 +41,7 @@ describe Twilio::SendOnTwilioService do
message = create(:message, message_type: 'incoming', inbox: twilio_inbox, account: account)
::Twilio::SendOnTwilioService.new(message: message).perform
expect(twilio_client).not_to have_received(:messages)
expect(message.reload.source_id).to be_nil
end
it 'if message has an source id' do