3scale/porta

View on GitHub
lib/exception_reporting.rb

Summary

Maintainability
A
0 mins
Test Coverage
module Kernel
  # Call the given block, and if it raises an exception, log it, report an error and supress it.
  def report_and_supress_exceptions
    if Rails.env.development? || Rails.env.test?
      yield
    else
      begin
        yield
      rescue Exception => exception
        message = "#{exception.class.name}: #{exception.message}\n"
        message << exception.backtrace.map { |line| "\t#{line}" }.join("\n")

        System::ErrorReporting.report_error(exception)
      end
    end
  end
end