rescue 500 error without messing Airbrake up
Asked Answered
S

1

6

I have Airbrake installed on my Rails app. However, I also want to perform some other actions when a 500 occurs. How do I rescue 500 errors without interfering with Airbrake?

Suitcase answered 22/11, 2012 at 12:48 Comment(0)
P
9

One way you can do this in your ApplicationController, you can put

unless Rails.application.config.consider_all_requests_local
  rescue_from Exception, with: :render_500
end

and later, a new render_500 method

def render_500(ex)
  notify_airbrake(ex)
  # render your template/message
end
Pickaninny answered 22/11, 2012 at 13:5 Comment(3)
Cool. Had to do unless Rails.application.config.consider_all_requests_local, but otherwise works.Suitcase
What version of Rails are you using? I'll happily update my answer to reflect this if it's current.Pickaninny
I'm using 3.2.9. I think the version I provided works for Rails 3 in general.Suitcase

© 2022 - 2024 — McMap. All rights reserved.