闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
452 B

  1. # frozen_string_literal: true
  2. class SidekiqErrorHandler
  3. BACKTRACE_LIMIT = 3
  4. def call(*)
  5. yield
  6. rescue Mastodon::HostValidationError
  7. # Do not retry
  8. rescue => e
  9. limit_backtrace_and_raise(e)
  10. ensure
  11. socket = Thread.current[:statsd_socket]
  12. socket&.close
  13. Thread.current[:statsd_socket] = nil
  14. end
  15. private
  16. def limit_backtrace_and_raise(e)
  17. e.set_backtrace(e.backtrace.first(BACKTRACE_LIMIT))
  18. raise e
  19. end
  20. end