Skip to content

Commit

Permalink
Pass installment to the processing error handler
Browse files Browse the repository at this point in the history
This way we can provide more flexibility on things that can be
done when an error occurs.

In the provided RailsLogger handler, we'll also print the ID
of the installment.
  • Loading branch information
kennyadsl committed Jul 13, 2021
1 parent e766894 commit ca3dcaf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/jobs/solidus_subscriptions/process_installment_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,19 @@
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
allow(SolidusSubscriptions::Checkout).to receive(:new).and_return(checkout)
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

Expand Down

0 comments on commit ca3dcaf

Please sign in to comment.