fix(voice): wrap Meta transport errors during accept as CallFailed

This commit is contained in:
Tanmay Deep Sharma
2026-04-30 18:52:51 +07:00
parent 0618e6e229
commit 2c025755e2
2 changed files with 12 additions and 5 deletions
@@ -51,9 +51,8 @@ class Whatsapp::CallService
end
def forward_answer_to_meta!
svc = call.inbox.channel.provider_service
raise Voice::CallErrors::CallFailed, 'Meta pre_accept failed' unless svc.pre_accept_call(call.provider_call_id, sdp_answer)
raise Voice::CallErrors::CallFailed, 'Meta accept failed' unless svc.accept_call(call.provider_call_id, sdp_answer)
invoke_provider!(:pre_accept_call, sdp_answer)
invoke_provider!(:accept_call, sdp_answer)
end
# Take ownership of the conversation if no one holds it; leave assignee alone otherwise (transfer via UI).
@@ -64,8 +63,8 @@ class Whatsapp::CallService
# Raise on Meta failure (bool false or transport error) so callers bail before
# finalizing local state — otherwise we'd mark a still-active call as ended
# and broadcast voice_call.ended while Meta thinks it's live.
def invoke_provider!(method)
success = call.inbox.channel.provider_service.public_send(method, call.provider_call_id)
def invoke_provider!(method, *)
success = call.inbox.channel.provider_service.public_send(method, call.provider_call_id, *)
raise Voice::CallErrors::CallFailed, "Meta #{method} failed" unless success
rescue Voice::CallErrors::CallFailed
raise
@@ -68,6 +68,14 @@ describe Whatsapp::CallService do
expect { described_class.new(call: call, agent: agent, sdp_answer: nil).accept }
.to raise_error(Voice::CallErrors::CallFailed, 'sdp_answer is required')
end
it 'wraps Meta transport exceptions as CallFailed and leaves the call ringing' do
allow(provider_service).to receive(:pre_accept_call).and_raise(Faraday::TimeoutError)
expect { described_class.new(call: call, agent: agent, sdp_answer: sdp_answer).accept }
.to raise_error(Voice::CallErrors::CallFailed)
expect(call.reload.status).to eq('ringing')
end
end
describe '#reject' do