To capture 500s inside the API gem "Grape" for Rails applications, add the following as a global exception handler:
rescue_from :all do |e| if Rails.env.development? raise e else Rollbar.error(e) error_response(message: "Internal server error", status: 500) end end
If you're not using Rails, you may first need to add the following to your Rakefile:
You may also need to add an
:environment task to your Rakefile if you haven't already defined one. At a bare minimum, this task should call
Rollbar.configure() and set your access token.
task :environment do Rollbar.configure do |config | config.access_token = '...' end end
To confirm that it worked, run:
$ rake rollbar:test
This will raise an exception within a test request; if it works, you'll see a stacktrace in the console, and the exception will appear in the Rollbar dashboard.
For more information on rollbar-gem, please see the docs here.
Updated about 1 month ago