Sending notices to Airbrake manually from controllers
Clone this wiki locally
DEPRECATION WARNING: The information presented on this page is related to Airbrake v4 only. If you seek for information for Airbrake v5, please refer to our README!
For the most part, Airbrake works for itself.
It intercepts the exception middleware calls, sends notifications and continues the middleware call chain.
If you want to log arbitrary things which you've rescued yourself from a controller, you can do something like this inside actions:
# ... rescue => ex env["airbrake.error_id"] = notify_airbrake(ex) flash[:failure] = 'Encryptions could not be rerouted, try again.' end
#notify_airbrake call will send the notice over to Airbrake for later
analysis. While in your controllers you use the
notify_airbrake method, anywhere
else in your code, use
To perform custom error processing after Airbrake has been notified, check for
env["airbrake.error_id"] inside your Rack middleware.
class AfterAirbrakeMiddleware def initialize(app) @app = app end def call(env) status, headers, body = @app.call(env) if env["airbrake.error_id"] body << "This error has been reported to Airbrake." end [status, headers, body] end end
Note that you have to call
Airbrake.notify method so it sets
env["airbrake.error_id"], see Informing the user when errors occur