From 12feed5bab1e6b916915629f51cd43c9d46abcdb Mon Sep 17 00:00:00 2001 From: Dmitriy Ivliev <3938172+moofkit@users.noreply.github.com> Date: Thu, 30 May 2024 09:57:44 +0300 Subject: [PATCH] fix error handling --- Gemfile | 1 + lib/sidekiq/rescue/server_middleware.rb | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index 9307060..3d6e45d 100644 --- a/Gemfile +++ b/Gemfile @@ -11,5 +11,6 @@ gem "rake", "~> 13.0" gem "rspec", "~> 3.0" gem "rubocop", "~> 1.21" +gem "rubocop-performance" gem "rubocop-rake" gem "rubocop-rspec" diff --git a/lib/sidekiq/rescue/server_middleware.rb b/lib/sidekiq/rescue/server_middleware.rb index 7052cdb..f6f69d1 100644 --- a/lib/sidekiq/rescue/server_middleware.rb +++ b/lib/sidekiq/rescue/server_middleware.rb @@ -21,12 +21,13 @@ def call(job_instance, job_payload, _queue, &block) private def sidekiq_rescue(job_payload, job_class) - klasses_to_rescue = job_class.sidekiq_rescue_options.keys.flatten yield - rescue *klasses_to_rescue => e - error_group, options = job_class.sidekiq_rescue_options.to_a.find do |error_group, _options| - Array(error_group).include?(e.class) + rescue StandardError => e + error_group, options = job_class.sidekiq_rescue_options.reverse_each.find do |error_group, _options| + Array(error_group).any? { |error| e.is_a?(error) } end + raise e unless error_group + rescue_error(e, error_group, options, job_payload) end