Skip to content

Instantly share code, notes, and snippets.

@martinstreicher
Created September 28, 2017 20:52
Show Gist options
  • Save martinstreicher/98ae3a3b4514856ec4ffd70b07487bc7 to your computer and use it in GitHub Desktop.
Save martinstreicher/98ae3a3b4514856ec4ffd70b07487bc7 to your computer and use it in GitHub Desktop.
Sidekiq Middleware to squelch some errors
module Middleware
SquelchedException = Class.new Exception
class SidekiqExceptionHandler
def call(worker, job, queue)
yield
rescue Exception => exception
notify exception, job, ignore: ignore_exception?(exception)
raise SquelchedException
end
private
def ignore_exception?(exception)
Bugsnag.configuration.ignore_classes.include?(exception.class.name)
end
def notify(exception, job, ignore: false)
args = job['args'].inject { |result, hash| result.merge hash }
ExceptionLoggingService.log(exception, args: args, ignore: ignore)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment