【问题标题】:notify_airbrake throws error on custom classesnotify_airbrake 在自定义类上引发错误
【发布时间】:2015-09-11 16:16:08
【问题描述】:

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

任何帮助将不胜感激!

【问题讨论】:

标签: ruby-on-rails airbrake


【解决方案1】:

您需要的方法是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-07-14
    • 1970-01-01
    • 2018-12-09
    • 2014-11-29
    • 1970-01-01
    • 1970-01-01
    • 2012-11-15
    • 1970-01-01
    • 2015-03-10
    相关资源
    最近更新 更多