herokuexceptionruby-on-rails-4.2timeoutexceptionrollbar

Rack-timeout results in 500 instead of 503


I'm using heroku's rack-timeout gem, along with dynamic error pages as described here.

However, when timeout raises an exception, it get's routed as a 500 error rather than 503.

I could catch the exception with a rescue_from in my application controller and manually route to errors#503, but that would prevent plugins like Rollbar from recording the exception.

Is there a way to get the correct error page rendered and ensure plugins like Rollbar still get wind of the exception?


Solution

  • I ended up using the rambulance gem, which provides a simple configuration option to solve this:

    # config/initializers/rambulance.rb
    
    Rambulance.setup do |config|
      config.rescue_responses = {
        "Rack::Timeout::RequestTimeoutException" => :service_unavailable
      }
    end
    

    The author has also written up some good reasons why not to use the approach I was previously using:

    Remove custom errors page section from the guides