Skip to content

Commit

Permalink
chore: Sentry issues (#4623)
Browse files Browse the repository at this point in the history
Fixes various issues reported on sentry

- Twilio channel creation validation errors
- Room Channel error with nil class
- Webhook Uri exception
  • Loading branch information
sojan-official committed May 6, 2022
1 parent 4f9d419 commit 8d2b719
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 9 deletions.
5 changes: 2 additions & 3 deletions app/builders/contact_builder.rb
Expand Up @@ -15,11 +15,10 @@ def account
end

def create_contact_inbox(contact)
::ContactInbox.create!(
::ContactInbox.create_with(hmac_verified: hmac_verified || false).find_or_create_by!(
contact_id: contact.id,
inbox_id: inbox.id,
source_id: source_id,
hmac_verified: hmac_verified || false
source_id: source_id
)
end

Expand Down
2 changes: 1 addition & 1 deletion app/builders/messages/facebook/message_builder.rb
Expand Up @@ -43,7 +43,7 @@ def build_contact
return if contact.present?

@contact = Contact.create!(contact_params.except(:remote_avatar_url))
@contact_inbox = ContactInbox.create(contact: contact, inbox: @inbox, source_id: @sender_id)
@contact_inbox = ContactInbox.find_or_create_by!(contact: contact, inbox: @inbox, source_id: @sender_id)
end

def build_message
Expand Down
2 changes: 2 additions & 0 deletions app/channels/room_channel.rb
Expand Up @@ -45,6 +45,8 @@ def current_user
end

def current_account
return if current_user.blank?

@current_account ||= if @current_user.is_a? Contact
@current_user.account
else
Expand Down
Expand Up @@ -7,7 +7,6 @@ def create
build_inbox
setup_webhooks if @twilio_channel.sms?
rescue StandardError => e
Sentry.capture_exception(e)
render_could_not_create_error(e.message)
end
end
Expand Down
Expand Up @@ -5,7 +5,7 @@ class Api::V1::Accounts::Conversations::BaseController < Api::V1::Accounts::Base
private

def conversation
@conversation ||= Current.account.conversations.find_by(display_id: params[:conversation_id])
@conversation ||= Current.account.conversations.find_by!(display_id: params[:conversation_id])
authorize @conversation.inbox, :show?
end
end
2 changes: 1 addition & 1 deletion app/finders/message_finder.rb
Expand Up @@ -22,7 +22,7 @@ def messages

def current_messages
if @params[:before].present?
messages.reorder('created_at desc').where('id < ?', @params[:before]).limit(20).reverse
messages.reorder('created_at desc').where('id < ?', @params[:before].to_i).limit(20).reverse
else
messages.reorder('created_at desc').limit(20).reverse
end
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/hook_job.rb
Expand Up @@ -9,7 +9,7 @@ def perform(hook, event_name, event_data = {})
process_dialogflow_integration(hook, event_name, event_data)
end
rescue StandardError => e
Sentry.capture_exception(e)
Rails.logger.error e
end

private
Expand Down
2 changes: 1 addition & 1 deletion lib/webhooks/trigger.rb
Expand Up @@ -7,7 +7,7 @@ def self.execute(url, payload)
timeout: 5
)
Rails.logger.info "Performed Request: Code - #{response.code}"
rescue *ExceptionList::REST_CLIENT_EXCEPTIONS => e
rescue *ExceptionList::REST_CLIENT_EXCEPTIONS, URI::InvalidURIError => e
Rails.logger.error "Exception: invalid webhook url #{url} : #{e.message}"
rescue StandardError => e
Rails.logger.error "Exception: invalid webhook url #{url} : #{e.message}"
Expand Down

0 comments on commit 8d2b719

Please sign in to comment.