Skip to content

Commit

Permalink
refactor: improve logging for channel callback controllers (#7555)
Browse files Browse the repository at this point in the history
Co-authored-by: Tejaswini Chile <tejaswini@chatwoot.com>
  • Loading branch information
vishnu-narayanan and tejaswinichile committed Jul 27, 2023
1 parent 9636478 commit 65c4ad7
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions app/controllers/api/v1/accounts/callbacks_controller.rb
Expand Up @@ -14,8 +14,18 @@ def register_facebook_page
@facebook_inbox = Current.account.inboxes.create!(name: inbox_name, channel: facebook_channel)
set_instagram_id(page_access_token, facebook_channel)
set_avatar(@facebook_inbox, page_id)
rescue StandardError => e
ChatwootExceptionTracker.new(e).capture_exception
end
rescue StandardError => e
ChatwootExceptionTracker.new(e).capture_exception
Rails.logger.error "Error in register_facebook_page: #{e.message}"
# Additional log statements
log_additional_info
end

def log_additional_info
Rails.logger.debug do
"user_access_token: #{params[:user_access_token]} , page_access_token: #{params[:page_access_token]} ,
page_id: #{params[:page_id]}, inbox_name: #{params[:inbox_name]}"
end
end

Expand All @@ -30,6 +40,8 @@ def set_instagram_id(page_access_token, facebook_channel)

instagram_id = response['instagram_business_account']['id']
facebook_channel.update(instagram_id: instagram_id)
rescue StandardError => e
Rails.logger.error "Error in set_instagram_id: #{e.message}"
end

# get params[:inbox_id], current_account. params[:omniauth_token]
Expand Down Expand Up @@ -61,6 +73,7 @@ def update_fb_page(fb_page_id, access_token)
fb_page&.reauthorized!
rescue StandardError => e
ChatwootExceptionTracker.new(e).capture_exception
Rails.logger.error "Error in update_fb_page: #{e.message}"
end
end

Expand All @@ -77,7 +90,7 @@ def long_lived_token(omniauth_token)
koala = Koala::Facebook::OAuth.new(GlobalConfigService.load('FB_APP_ID', ''), GlobalConfigService.load('FB_APP_SECRET', ''))
koala.exchange_access_token_info(omniauth_token)['access_token']
rescue StandardError => e
Rails.logger.error e
Rails.logger.error "Error in long_lived_token: #{e.message}"
end

def mark_already_existing_facebook_pages(data)
Expand Down

0 comments on commit 65c4ad7

Please sign in to comment.