mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-02 12:08:01 +00:00
fix: Disable marking IMAP connection as invalid for Standard Errors (#4764)
This commit is contained in:
@@ -6,13 +6,12 @@ class Inboxes::FetchImapEmailsJob < ApplicationJob
|
|||||||
def perform(channel)
|
def perform(channel)
|
||||||
return unless should_fetch_email?(channel)
|
return unless should_fetch_email?(channel)
|
||||||
|
|
||||||
process_mail_for_channel(channel)
|
fetch_mail_for_channel(channel)
|
||||||
# clearing old failures like timeouts since the mail is now successfully processed
|
# clearing old failures like timeouts since the mail is now successfully processed
|
||||||
channel.reauthorized!
|
channel.reauthorized!
|
||||||
rescue Errno::ECONNREFUSED, Net::OpenTimeout, Net::IMAP::NoResponseError
|
rescue Errno::ECONNREFUSED, Net::OpenTimeout, Net::IMAP::NoResponseError
|
||||||
channel.authorization_error!
|
channel.authorization_error!
|
||||||
rescue StandardError => e
|
rescue StandardError => e
|
||||||
channel.authorization_error!
|
|
||||||
ChatwootExceptionTracker.new(e, account: channel.account).capture_exception
|
ChatwootExceptionTracker.new(e, account: channel.account).capture_exception
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -22,7 +21,7 @@ class Inboxes::FetchImapEmailsJob < ApplicationJob
|
|||||||
channel.imap_enabled? && !channel.reauthorization_required?
|
channel.imap_enabled? && !channel.reauthorization_required?
|
||||||
end
|
end
|
||||||
|
|
||||||
def process_mail_for_channel(channel)
|
def fetch_mail_for_channel(channel)
|
||||||
# TODO: rather than setting this as default method for all mail objects, lets if can do new mail object
|
# TODO: rather than setting this as default method for all mail objects, lets if can do new mail object
|
||||||
# using Mail.retriever_method.new(params)
|
# using Mail.retriever_method.new(params)
|
||||||
Mail.defaults do
|
Mail.defaults do
|
||||||
@@ -36,12 +35,18 @@ class Inboxes::FetchImapEmailsJob < ApplicationJob
|
|||||||
new_mails = false
|
new_mails = false
|
||||||
|
|
||||||
Mail.find(what: :last, count: 10, order: :desc).each do |inbound_mail|
|
Mail.find(what: :last, count: 10, order: :desc).each do |inbound_mail|
|
||||||
if inbound_mail.date.utc >= channel.imap_inbox_synced_at
|
next unless inbound_mail.date.utc >= channel.imap_inbox_synced_at
|
||||||
Imap::ImapMailbox.new.process(inbound_mail, channel)
|
|
||||||
|
process_mail(inbound_mail, channel)
|
||||||
new_mails = true
|
new_mails = true
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
channel.update(imap_inbox_synced_at: Time.now.utc) if new_mails
|
channel.update(imap_inbox_synced_at: Time.now.utc) if new_mails
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def process_mail(inbound_mail, channel)
|
||||||
|
Imap::ImapMailbox.new.process(inbound_mail, channel)
|
||||||
|
rescue StandardError => e
|
||||||
|
ChatwootExceptionTracker.new(e, account: channel.account).capture_exception
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -12,8 +12,11 @@ class ChatwootExceptionTracker
|
|||||||
end
|
end
|
||||||
|
|
||||||
def capture_exception
|
def capture_exception
|
||||||
capture_exception_with_sentry if ENV['SENTRY_DSN'].present?
|
if ENV['SENTRY_DSN'].present?
|
||||||
# Implement other providers like honeybadger, rollbar etc in future
|
capture_exception_with_sentry
|
||||||
|
else
|
||||||
|
Rails.logger.error @exception
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe ChatwootExceptionTracker do
|
describe ChatwootExceptionTracker do
|
||||||
it 'returns nil if no tracker is configured' do
|
it 'use rails logger if no tracker is configured' do
|
||||||
expect(described_class.new('random').capture_exception).to eq(nil)
|
expect(Rails.logger).to receive(:error).with('random')
|
||||||
|
described_class.new('random').capture_exception
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with sentry DSN' do
|
context 'with sentry DSN' do
|
||||||
|
|||||||
Reference in New Issue
Block a user