notify_airbrake会在自定义类上引发错误

时间:2015-09-11 16:16:09

标签: ruby-on-rails airbrake

我们在整个代码库中使用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

任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:4)

您需要的方法是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