From c9e26197b0abbe50b029c368017243314d572884 Mon Sep 17 00:00:00 2001 From: Alberto Vena Date: Mon, 12 Jul 2021 15:29:53 +0200 Subject: Logs an error in the Rails logs when installment processing fails At the moment, by default, all installment prceissing errors are swallowed and there's no way for a developer to understand what's happening. Of course they can create a custom handler with the processing_error_handler configuration provided but usually, when the first errors happen, it's too late and those errors are lost. We are not raising errors of this job because if there's a retry mechanism in place for Active Job, the installment will be reprocessed twice. Once by Active Job and once by the installment retry mechanism already provided by the extension. Logging to Rails.error is a middle-ground that allows to intercept the message of the exception. Still, creating a custom handler based on the bug tracker/exception handler used is the suggested option here. --- lib/solidus_subscriptions/configuration.rb | 9 +++++++-- lib/solidus_subscriptions/engine.rb | 1 + .../processing_error_handlers/rails_logger.rb | 23 ++++++++++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 lib/solidus_subscriptions/processing_error_handlers/rails_logger.rb (limited to 'lib/solidus_subscriptions') diff --git a/lib/solidus_subscriptions/configuration.rb b/lib/solidus_subscriptions/configuration.rb index 9d6c3d2..350fabc 100644 --- a/lib/solidus_subscriptions/configuration.rb +++ b/lib/solidus_subscriptions/configuration.rb @@ -4,14 +4,14 @@ module SolidusSubscriptions class Configuration attr_accessor( :maximum_total_skips, :maximum_reprocessing_time, :churn_buster_account_id, - :churn_buster_api_key, :clear_past_installments, :processing_error_handler + :churn_buster_api_key, :clear_past_installments ) attr_writer( :success_dispatcher_class, :failure_dispatcher_class, :payment_failed_dispatcher_class, :out_of_stock_dispatcher, :maximum_successive_skips, :reprocessing_interval, :minimum_cancellation_notice, :processing_queue, :subscription_line_item_attributes, - :subscription_attributes, :subscribable_class, :order_creator_class + :subscription_attributes, :subscribable_class, :order_creator_class, :processing_error_handler ) def success_dispatcher_class @@ -34,6 +34,11 @@ module SolidusSubscriptions @out_of_stock_dispatcher_class.constantize end + def processing_error_handler + @processing_error_handler ||= 'SolidusSubscriptions::ProcessingErrorHandlers::RailsLogger' + @processing_error_handler.constantize + end + def maximum_successive_skips @maximum_successive_skips ||= 1 end diff --git a/lib/solidus_subscriptions/engine.rb b/lib/solidus_subscriptions/engine.rb index 0f274d8..2d361cf 100644 --- a/lib/solidus_subscriptions/engine.rb +++ b/lib/solidus_subscriptions/engine.rb @@ -6,6 +6,7 @@ require 'solidus_subscriptions' require 'solidus_subscriptions/permitted_attributes' require 'solidus_subscriptions/configuration' require 'solidus_subscriptions/processor' +require 'solidus_subscriptions/processing_error_handlers/rails_logger' module SolidusSubscriptions class Engine < Rails::Engine diff --git a/lib/solidus_subscriptions/processing_error_handlers/rails_logger.rb b/lib/solidus_subscriptions/processing_error_handlers/rails_logger.rb new file mode 100644 index 0000000..d209123 --- /dev/null +++ b/lib/solidus_subscriptions/processing_error_handlers/rails_logger.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +module SolidusSubscriptions + module ProcessingErrorHandlers + class RailsLogger + def self.call(exception) + new(exception).call + end + + def initialize(exception) + @exception = exception + end + + def call + Rails.logger.error exception.message + end + + private + + attr_reader :exception + end + end +end -- cgit v1.2.3