1

We use airbrake throughout our codebase which works great except for custom classes that do not inherit from a Rails hierarchy (i.e. ActiveRecord).

Some code:

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

In airbrake we see:

NoMethodError: undefined method `notify_airbrake' for Offer:Class

As the error. I want the actual error and not an error for reporting an error!

Our airbrake.rb file:

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

Any help would be appreciated!

dipole_moment
  • 5,266
  • 4
  • 39
  • 55
  • 3
    Hi! Try `Airbrake.notify(e)` instead of `notify_airbrake(e)`. – kyrylo Sep 11 '15 at 16:19
  • `notify_airbrake` is for use in controllers only. ref: https://github.com/airbrake/airbrake/blob/master/lib/airbrake/rails/action_controller.rb – Kris Feb 28 '17 at 14:51

1 Answers1

5

The method you need is Airbrake.notify_or_ignore(). For your given example:

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

More detail can be found here: https://github.com/airbrake/airbrake/wiki/Using-Airbrake-with-plain-Ruby

zefer
  • 558
  • 3
  • 9