From bc768bf04f4199bebf6d0e30ed226e02405deeb3 Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Mon, 11 May 2026 10:58:23 +0530 Subject: [PATCH] chore: verbosely log errors for leadsquare activity failure (#14407) --- .../crm/leadsquared/processor_service.rb | 16 ++++++++++++---- .../crm/leadsquared/processor_service_spec.rb | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/app/services/crm/leadsquared/processor_service.rb b/app/services/crm/leadsquared/processor_service.rb index ef33718f2..9ffa3d12c 100644 --- a/app/services/crm/leadsquared/processor_service.rb +++ b/app/services/crm/leadsquared/processor_service.rb @@ -89,11 +89,19 @@ class Crm::Leadsquared::ProcessorService < Crm::BaseProcessorService metadata[metadata_key] = activity_id store_conversation_metadata(conversation, metadata) rescue Crm::Leadsquared::Api::BaseClient::ApiError => e - ChatwootExceptionTracker.new(e, account: @account).capture_exception - Rails.logger.error "LeadSquared API error in #{activity_type} activity: #{e.message}" + log_activity_error(e, activity_type, conversation, payload: { lead_id: lead_id, activity_code: activity_code, activity_note: activity_note }) rescue StandardError => e - ChatwootExceptionTracker.new(e, account: @account).capture_exception - Rails.logger.error "Error creating #{activity_type} activity in LeadSquared: #{e.message}" + log_activity_error(e, activity_type, conversation) + end + + def log_activity_error(error, activity_type, conversation, payload: nil) + ChatwootExceptionTracker.new(error, account: @account).capture_exception + context = "account_id=#{conversation.account_id}, conversation_display_id=#{conversation.display_id}" + if payload + context += ", http_status=#{error.code}, prospect_id=#{payload[:lead_id]}, " \ + "activity_event=#{payload[:activity_code]}, note_bytes=#{payload[:activity_note].to_s.bytesize}" + end + Rails.logger.error("LeadSquared #{activity_type} activity failed: #{error.message} (#{context})") end def get_activity_code(key) diff --git a/spec/services/crm/leadsquared/processor_service_spec.rb b/spec/services/crm/leadsquared/processor_service_spec.rb index 7008eb064..7b99721c5 100644 --- a/spec/services/crm/leadsquared/processor_service_spec.rb +++ b/spec/services/crm/leadsquared/processor_service_spec.rb @@ -157,7 +157,7 @@ RSpec.describe Crm::Leadsquared::ProcessorService do it 'logs the error' do service.handle_conversation_created(conversation) - expect(Rails.logger).to have_received(:error).with(/Error creating conversation activity/) + expect(Rails.logger).to have_received(:error).with(/LeadSquared conversation activity failed/) end end end