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

@@ -117,5 +117,54 @@ describe Facebook::SendOnFacebookService do
expect(message.reload.status).to eq('failed')
end
end
context 'when deliver_message fails' do
let(:message) { create(:message, message_type: 'outgoing', inbox: facebook_inbox, account: account, conversation: conversation) }
it 'handles JSON parse errors' do
allow(bot).to receive(:deliver).and_return('invalid_json')
described_class.new(message: message).perform
expect(message.reload.status).to eq('failed')
expect(message.external_error).to eq('Facebook was unable to process this request')
end
it 'handles timeout errors' do
allow(bot).to receive(:deliver).and_raise(Net::OpenTimeout)
described_class.new(message: message).perform
expect(message.reload.status).to eq('failed')
expect(message.external_error).to eq('Request timed out, please try again later')
end
it 'handles facebook error with code' do
error_response = {
error: {
message: 'Invalid OAuth access token.',
type: 'OAuthException',
code: 190,
fbtrace_id: 'BLBz/WZt8dN'
}
}.to_json
allow(bot).to receive(:deliver).and_return(error_response)
described_class.new(message: message).perform
expect(message.reload.status).to eq('failed')
expect(message.external_error).to eq('190 - Invalid OAuth access token.')
end
it 'handles successful delivery with message_id' do
success_response = {
message_id: 'mid.1456970487936:c34767dfe57ee6e339'
}.to_json
allow(bot).to receive(:deliver).and_return(success_response)
described_class.new(message: message).perform
expect(message.reload.source_id).to eq('mid.1456970487936:c34767dfe57ee6e339')
expect(message.status).not_to eq('failed')
end
end
end
end