1

我们在整个代码库中都使用了 airbrake,除了不从 Rails 层次结构继承的自定义类(即 ActiveRecord)外,它工作得很好。

一些代码:

class Offer
  def counter(amount, qty=1)
    begin
      offers_response = viyet_mage_rest_client.counter_offer(@id.to_i, amount, qty.to_i)
    rescue => e
      notify_airbrake(e)
      offers_response = []
    end
  end
end

在空气制动中,我们看到:

NoMethodError: undefined method `notify_airbrake' for Offer:Class

作为错误。我想要实际的错误而不是报告错误的错误!

我们的 airbrake.rb 文件:

if Rails.env.production? || Rails.env.staging? 
  Airbrake.configure do |config|
    config.api_key = Settings.airbrake.api_key
    config.secure = true
  end
end

任何帮助,将不胜感激!

4

1 回答 1

5

你需要的方法是Airbrake.notify_or_ignore()。对于您给定的示例:

class Offer
  def counter(amount, qty=1)
    begin
      offers_response = viyet_mage_rest_client.counter_offer(@id.to_i, amount, qty.to_i)
    rescue => e
      Airbrake.notify_or_ignore(e)
      offers_response = []
    end
  end
end

更多细节可以在这里找到:https ://github.com/airbrake/airbrake/wiki/Using-Airbrake-with-plain-Ruby

于 2015-09-11T16:25:17.733 回答