Skip to content

Informing the user when errors occur

shime edited this page Oct 27, 2012 · 1 revision

The airbrake gem is capable of telling the user information about the error that just happened via the user_information option. They can give this error number in bug reports, for example. By default, if your 500.html contains the text

<!-- AIRBRAKE ERROR -->

then that comment will be replaced with the text "Airbrake Error [errnum]". You can modify the text of the informer by setting config.user_information. Airbrake will replace "{{ error_id }}" with the ID of the error that is returned from Airbrake.

Airbrake.configure do |config|
   #...
   config.user_information = "<p>Tell the devs that it was <strong>{{ error_id }}</strong>'s fault.</p>"
end

You can also turn the middleware that handles this completely off by setting config.user_information to false.

Note that this feature is reading the error id from env['airbrake.error_id']. When the exception is caught automatically in a controller, Airbrake sets that value. If you're, however, calling the Airbrake methods like Airbrake#notify or Airbrake#notify_or_ignore, please make sure you set that value. So the proper way of calling the "manual" methods would be env['airbrake.error_id'] = Airbrake.notify_or_ignore(...).