Files
openfoodnetwork/app/controllers/concerns/request_timeouts.rb
Matt-Yorkley 1b112961d1 Handle request timeouts explicitly with rack-timeout
Puma doesn't terminate execution of long-running requests by default.
2021-07-31 13:11:10 +01:00

24 lines
555 B
Ruby

# frozen_string_literal: true
module RequestTimeouts
extend ActiveSupport::Concern
included do
rescue_from Rack::Timeout::RequestTimeoutException, with: :timeout_response if defined? Rack::Timeout
end
private
def timeout_response(_exception = nil)
respond_to do |type|
type.html {
render status: :gateway_timeout,
file: Rails.root.join("public/500.html"),
formats: [:html],
layout: nil
}
type.all { render status: :gateway_timeout, body: nil }
end
end
end