feat: handle Channel errors (#11015)

This PR adds missing error handlers for the following channels and cases

1. WhatsApp - Generic Handlers for both Cloud and 360Dialog (Deprecated)
2. Instagram - Handler for a case where there is an HTTP error instead
of an `:error` in the 200 response
3. Facebook - Errors from the two sentry issues
([Net::OpenTimeout](https://chatwoot-p3.sentry.io/issues/6164805227) &
[JSON::ParserError](https://chatwoot-p3.sentry.io/issues/5903200786))
4. SMS: Generic handlers for Bandwidth SMS

#### Checklist

- [x] Bandwidth SMS
- [x] Whatsapp Cloud + 360 Dialog
- [x] Twilio SMS
- [x] Line
- [x] Telegram
- [x] Instagram
- [x] Facebook
- [x] GMail
- [x] 365 Mail
- [x] SMTP Mail

---------

Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
This commit is contained in:
Shivam Mishra
2025-03-06 20:09:47 +05:30
committed by GitHub
parent 7e1458fd32
commit 8d85a02ca9
12 changed files with 324 additions and 124 deletions

View File

@@ -263,4 +263,56 @@ describe Whatsapp::Providers::WhatsappCloudService do
end
end
end
describe '#handle_error' do
let(:error_message) { 'Invalid message format' }
let(:error_response) do
{
'error' => {
'message' => error_message,
'code' => 100
}
}
end
let(:error_response_object) do
instance_double(
HTTParty::Response,
body: error_response.to_json,
parsed_response: error_response
)
end
before do
allow(Rails.logger).to receive(:error)
end
context 'when there is a message' do
it 'logs error and updates message status' do
service.instance_variable_set(:@message, message)
service.send(:handle_error, error_response_object)
expect(message.reload.status).to eq('failed')
expect(message.reload.external_error).to eq(error_message)
end
end
context 'when error message is blank' do
let(:error_response_object) do
instance_double(
HTTParty::Response,
body: '{}',
parsed_response: {}
)
end
it 'logs error but does not update message' do
service.instance_variable_set(:@message, message)
service.send(:handle_error, error_response_object)
expect(message.reload.status).not_to eq('failed')
expect(message.reload.external_error).to be_nil
end
end
end
end