diff --git a/app/jobs/solidus_subscriptions/process_installment_job.rb b/app/jobs/solidus_subscriptions/process_installment_job.rb index 53270e5f..84d077a8 100644 --- a/app/jobs/solidus_subscriptions/process_installment_job.rb +++ b/app/jobs/solidus_subscriptions/process_installment_job.rb @@ -7,7 +7,7 @@ class ProcessInstallmentJob < ApplicationJob def perform(installment) Checkout.new(installment).process rescue StandardError => e - SolidusSubscriptions.configuration.processing_error_handler&.call(e) + SolidusSubscriptions.configuration.processing_error_handler&.call(e, installment) end end end diff --git a/lib/solidus_subscriptions/processing_error_handlers/rails_logger.rb b/lib/solidus_subscriptions/processing_error_handlers/rails_logger.rb index 8bd8bb07..d0953cc1 100644 --- a/lib/solidus_subscriptions/processing_error_handlers/rails_logger.rb +++ b/lib/solidus_subscriptions/processing_error_handlers/rails_logger.rb @@ -3,18 +3,20 @@ module SolidusSubscriptions module ProcessingErrorHandlers class RailsLogger - def self.call(exception) - new(exception).call + def self.call(exception, installment = nil) + new(exception, installment).call end - attr_reader :exception + attr_reader :exception, :installment - def initialize(exception) + def initialize(exception, installment = nil) @exception = exception + @installment = installment end def call - Rails.logger.error exception.message + Rails.logger.error("Error processing installment with ID=#{installment.id}:") if installment + Rails.logger.error(exception.message) end end end diff --git a/spec/jobs/solidus_subscriptions/process_installment_job_spec.rb b/spec/jobs/solidus_subscriptions/process_installment_job_spec.rb index 7211cfeb..767d6506 100644 --- a/spec/jobs/solidus_subscriptions/process_installment_job_spec.rb +++ b/spec/jobs/solidus_subscriptions/process_installment_job_spec.rb @@ -12,7 +12,8 @@ end context 'when handling #perform errors' do - it 'by default logs exception data without raising exceptions' do + it 'by default logs exception data without raising exceptions' do # rubocop:disable RSpec/MultipleExpectations + installment = build_stubbed(:installment) checkout = instance_double(SolidusSubscriptions::Checkout).tap do |c| allow(c).to receive(:process).and_raise('test error') end @@ -20,9 +21,10 @@ allow(Rails.logger).to receive(:error) expect { - described_class.perform_now(build_stubbed(:installment)) + described_class.perform_now(installment) }.not_to raise_error + expect(Rails.logger).to have_received(:error).with("Error processing installment with ID=#{installment.id}:").ordered expect(Rails.logger).to have_received(:error).with("test error").ordered end