Last active
August 11, 2023 00:51
-
-
Save khoan/d077c639138d687131302169fc716338 to your computer and use it in GitHub Desktop.
skip reporting transient errors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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