Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/services/twilio_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def sanitize_errors
rescue Twilio::REST::RestError => error
sanitize_phone_number(error.message)
raise
rescue Faraday::TimeoutError
rescue Faraday::TimeoutError, Faraday::ConnectionFailed
retry unless (tries -= 1).zero?
raise_custom_timeout_error
end
Expand Down
30 changes: 30 additions & 0 deletions spec/services/twilio_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,21 @@
expect { service.place_call(to: '+123456789012', url: 'https://twimlet.com') }.
to raise_error(Twilio::REST::RestError, message)
end

it 'rescues failed connection errors, retries, then raises a custom Twilio error' do
TwilioService::Utils.telephony_service = FakeVoiceCall
error_code = 4_815_162_342
status_code = 4_815_162_342

message = "[HTTP #{status_code}] #{error_code} : timeout\n\n"
service = TwilioService::Utils.new

expect(service.send(:client).calls).to receive(:create).twice.
and_raise(Faraday::ConnectionFailed.new('error'))

expect { service.place_call(to: '+123456789012', url: 'https://twimlet.com') }.
to raise_error(Twilio::REST::RestError, message)
end
end

describe '#send_sms' do
Expand Down Expand Up @@ -182,5 +197,20 @@
expect { service.send_sms(to: '+123456789012', body: 'test') }.
to raise_error(Twilio::REST::RestError, message)
end

it 'rescues failed connection errors, retries, then raises a custom Twilio error' do
TwilioService::Utils.telephony_service = FakeSms
error_code = 4_815_162_342
status_code = 4_815_162_342

message = "[HTTP #{status_code}] #{error_code} : timeout\n\n"
service = TwilioService::Utils.new

expect(service.send(:client).messages).to receive(:create).twice.
and_raise(Faraday::ConnectionFailed.new('error'))

expect { service.send_sms(to: '+123456789012', body: 'test') }.
to raise_error(Twilio::REST::RestError, message)
end
end
end