chore: Fix sentry issues (#4863)

Fix sentry issues.

Fixes #4815, #4814, #4811, #4809
This commit is contained in:
Aswin Dev P.S 2022-06-15 16:20:19 +05:30 committed by GitHub
parent 067c905329
commit 9015d83679
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 51 additions and 12 deletions

View file

@ -43,14 +43,18 @@ class Api::V1::Accounts::InboxesController < Api::V1::Accounts::BaseController
def update
@inbox.update!(permitted_params.except(:channel))
@inbox.update_working_hours(params.permit(working_hours: Inbox::OFFISABLE_ATTRS)[:working_hours]) if params[:working_hours]
update_inbox_working_hours
channel_attributes = get_channel_attributes(@inbox.channel_type)
# Inbox update doesn't necessarily need channel attributes
return if permitted_params(channel_attributes)[:channel].blank?
if @inbox.inbox_type == 'Email'
begin
validate_email_channel(channel_attributes)
rescue StandardError => e
render json: { message: e }, status: :unprocessable_entity and return
end
@inbox.channel.reauthorized!
end
@ -58,6 +62,10 @@ class Api::V1::Accounts::InboxesController < Api::V1::Accounts::BaseController
update_channel_feature_flags
end
def update_inbox_working_hours
@inbox.update_working_hours(params.permit(working_hours: Inbox::OFFISABLE_ATTRS)[:working_hours]) if params[:working_hours]
end
def agent_bot
@agent_bot = @inbox.agent_bot
end
@ -89,12 +97,6 @@ class Api::V1::Accounts::InboxesController < Api::V1::Accounts::BaseController
@agent_bot = AgentBot.find(params[:agent_bot]) if params[:agent_bot]
end
def inbox_name(channel)
return channel.try(:bot_name) if channel.is_a?(Channel::Telegram)
permitted_params[:name]
end
def create_channel
return unless %w[web_widget api email line telegram whatsapp sms].include?(permitted_params[:channel][:type])

View file

@ -1,4 +1,10 @@
module Api::V1::InboxesHelper
def inbox_name(channel)
return channel.try(:bot_name) if channel.is_a?(Channel::Telegram)
permitted_params[:name]
end
def validate_email_channel(attributes)
channel_data = permitted_params(attributes)[:channel]
@ -19,8 +25,7 @@ module Api::V1::InboxesHelper
enable_ssl: channel_data[:imap_enable_ssl] }
end
Mail.connection do # rubocop:disable:block
end
check_imap_connection(channel_data)
end
def validate_smtp(channel_data)
@ -32,6 +37,25 @@ module Api::V1::InboxesHelper
check_smtp_connection(channel_data, smtp)
end
def check_imap_connection(channel_data)
Mail.connection {} # rubocop:disable:block
rescue SocketError => e
raise StandardError, I18n.t('errors.inboxes.imap.socket_error')
rescue Net::IMAP::NoResponseError => e
raise StandardError, I18n.t('errors.inboxes.imap.no_response_error')
rescue Errno::EHOSTUNREACH => e
raise StandardError, I18n.t('errors.inboxes.imap.host_unreachable_error')
rescue Net::OpenTimeout => e
raise StandardError,
I18n.t('errors.inboxes.imap.connection_timed_out_error', address: channel_data[:imap_address], port: channel_data[:imap_port])
rescue Net::IMAP::Error => e
raise StandardError, I18n.t('errors.inboxes.imap.connection_closed_error')
rescue StandardError => e
raise StandardError, e.message
ensure
Rails.logger.error e if e.present?
end
def check_smtp_connection(channel_data, smtp)
smtp.start(channel_data[:smtp_domain], channel_data[:smtp_login], channel_data[:smtp_password],
channel_data[:smtp_authentication]&.to_sym || :login)

View file

@ -156,7 +156,7 @@ export default {
await this.$store.dispatch('inboxes/updateInboxIMAP', payload);
this.showAlert(this.$t('INBOX_MGMT.IMAP.EDIT.SUCCESS_MESSAGE'));
} catch (error) {
this.showAlert(this.$t('INBOX_MGMT.IMAP.EDIT.ERROR_MESSAGE'));
this.showAlert(error.message);
}
},
},

View file

@ -216,8 +216,12 @@ export const actions = {
commit(types.default.SET_INBOXES_UI_FLAG, {
isUpdatingIMAP: false,
});
if (error.response?.data?.message) {
throw new Error(error.response?.data?.message);
} else {
throw new Error(error);
}
}
},
updateInboxSMTP: async (
{ commit },

View file

@ -21,6 +21,8 @@ module MailboxHelper
end
def add_attachments_to_message
return if @message.blank?
processed_mail.attachments.each do |mail_attachment|
attachment = @message.attachments.new(
account_id: @conversation.account_id,

View file

@ -46,6 +46,13 @@ en:
contacts:
import:
failed: File is blank
inboxes:
imap:
socket_error: Please check the network connection, IMAP address and try again.
no_response_error: Please check the IMAP credentials and try again.
host_unreachable_error: Host unreachable, Please check the IMAP address, IMAP port and try again.
connection_timed_out_error: Connection timed out for %{address}:%{port}
connection_closed_error: Connection closed.
reports:
period: Reporting period %{since} to %{until}