chore: Rescue Oauth2::Error and mark the channel as inactive (#9358)
Co-authored-by: Sojan <sojan@pepalo.com>
This commit is contained in:
@@ -36,6 +36,9 @@ class Inboxes::FetchImapEmailsJob < MutexApplicationJob
|
|||||||
inbound_emails.map do |inbound_mail|
|
inbound_emails.map do |inbound_mail|
|
||||||
process_mail(inbound_mail, channel)
|
process_mail(inbound_mail, channel)
|
||||||
end
|
end
|
||||||
|
rescue OAuth2::Error => e
|
||||||
|
Rails.logger.error "Error for email channel - #{channel.inbox.id} : #{e.message}"
|
||||||
|
channel.authorization_error!
|
||||||
end
|
end
|
||||||
|
|
||||||
def process_mail(inbound_mail, channel)
|
def process_mail(inbound_mail, channel)
|
||||||
|
|||||||
@@ -69,6 +69,24 @@ RSpec.describe Inboxes::FetchImapEmailsJob do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when IMAP OAuth errors out' do
|
||||||
|
it 'marks the connection as requiring authorization' do
|
||||||
|
error_response = double
|
||||||
|
oauth_error = OAuth2::Error.new(error_response)
|
||||||
|
|
||||||
|
allow(Imap::MicrosoftFetchEmailService).to receive(:new)
|
||||||
|
.with(channel: microsoft_imap_email_channel, interval: 1)
|
||||||
|
.and_raise(oauth_error)
|
||||||
|
|
||||||
|
allow(Redis::Alfred).to receive(:incr)
|
||||||
|
|
||||||
|
expect(Redis::Alfred).to receive(:incr)
|
||||||
|
.with("AUTHORIZATION_ERROR_COUNT:channel_email:#{microsoft_imap_email_channel.id}")
|
||||||
|
|
||||||
|
described_class.perform_now(microsoft_imap_email_channel)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'when the fetch service returns the email objects' do
|
context 'when the fetch service returns the email objects' do
|
||||||
let(:inbound_mail) { create_inbound_email_from_fixture('welcome.eml').mail }
|
let(:inbound_mail) { create_inbound_email_from_fixture('welcome.eml').mail }
|
||||||
let(:mailbox) { double }
|
let(:mailbox) { double }
|
||||||
|
|||||||
Reference in New Issue
Block a user