Skip to content

Instantly share code, notes, and snippets.

@khoan
Last active August 11, 2023 00:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save khoan/d077c639138d687131302169fc716338 to your computer and use it in GitHub Desktop.
Save khoan/d077c639138d687131302169fc716338 to your computer and use it in GitHub Desktop.
skip reporting transient errors
class TransientError < StandardError
def report_error!
@report_error = true
end
# skip error reporting by default until we're told to report error
def skip_reporting_error?
!@report_error
end
end
Honeybadger.configure do |config|
config.before_notify do |notice|
if Sidekiq.server? && notice.exception < TransientError && notice.exception.skip_reporting_error?
notice.halt!
end
end
end
class ApplicationJob
include Sidekiq::Job
sidekiq_retries_exhausted do |_message, exception|
exception.report_error! if exception.respond_to?(:report_error!)
end
end
class MyJob < ApplicationJob
class MyError < TransientError; end
def perform
raise MyError
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment