Fix: skip invalid access token from sentry (#6639)

This commit is contained in:
Tejaswini Chile
2023-03-09 16:28:45 +05:30
committed by GitHub
parent 54b7c98795
commit fbdc79df76
2 changed files with 18 additions and 2 deletions

View File

@@ -9,9 +9,8 @@ class Facebook::SendOnFacebookService < Base::SendOnChannelService
send_message_to_facebook fb_text_message_params if message.content.present?
send_message_to_facebook fb_attachment_message_params if message.attachments.present?
rescue Facebook::Messenger::FacebookError => e
ChatwootExceptionTracker.new(e, account: message.account, user: message.sender).capture_exception
# TODO : handle specific errors or else page will get disconnected
# channel.authorization_error!
handle_facebook_error(e)
end
def send_message_to_facebook(delivery_params)
@@ -67,4 +66,13 @@ class Facebook::SendOnFacebookService < Base::SendOnChannelService
def last_incoming_message
conversation.messages.incoming.last
end
def handle_facebook_error(exception)
# Refer: https://github.com/jgorset/facebook-messenger/blob/64fe1f5cef4c1e3fca295b205037f64dfebdbcab/lib/facebook/messenger/error.rb
if exception.to_s.include?('The session has been invalidated') || exception.to_s.include?('Error validating access token')
channel.authorization_error!
else
ChatwootExceptionTracker.new(exception, account: message.account, user: message.sender).capture_exception
end
end
end