Customizing Rollbar Reporting

By default, the Rollbar client will report any uncaught exception. But you can also report exceptions and other types of events manually.

For example, you may want to trap an exception, report it, and then proceed with some default logic. In Twitalytics, this is necessary when a nonexistent post is requested. Open the app/controllers/posts_controller.rb file, and find the set_post method. Modify it to look like this:

 def​ set_post
  @post = Post.find(params[​:id​])
 rescue​ ActiveRecord::RecordNotFound => e
  Rollbar.error(e, ​"Requested an unknown Post"​)
  Rollbar.log(​"Defaulting to first Post"​)
  @post = Post.first
 end

The rescue clause calls Rollbar.error if an ActiveRecord::RecordNotFound is raised. ...

Get Deploying with JRuby 9k now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.