diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2017-04-02 19:43:09 +0200 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2017-04-02 19:43:44 +0200 |
commit | 5b12624847f6a599e1bbb3b24fc87c3b222e6716 (patch) | |
tree | f6fda89ae5288e5e48d12c534562f10aca290f11 | |
parent | 34ff11c49600e2ca8547f4044f2c73b33aa70c34 (diff) |
Add proper error page for request timeouts
-rw-r--r-- | Gemfile | 2 | ||||
-rw-r--r-- | app/controllers/application_controller.rb | 8 | ||||
-rw-r--r-- | app/views/errors/503.html.haml | 5 | ||||
-rw-r--r-- | config/initializers/timeout.rb | 4 |
4 files changed, 17 insertions, 2 deletions
diff --git a/Gemfile b/Gemfile index 440f2e87b..764010d5d 100644 --- a/Gemfile +++ b/Gemfile @@ -50,6 +50,7 @@ gem 'rails-settings-cached' gem 'simple-navigation' gem 'statsd-instrument' gem 'ruby-oembed', require: 'oembed' +gem 'rack-timeout' gem 'react-rails' gem 'browserify-rails' @@ -89,5 +90,4 @@ group :production do gem 'rails_12factor' gem 'redis-rails' gem 'lograge' - gem 'rack-timeout' end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index ef9364897..abfb5bb8c 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -12,6 +12,7 @@ class ApplicationController < ActionController::Base rescue_from ActionController::RoutingError, with: :not_found rescue_from ActiveRecord::RecordNotFound, with: :not_found rescue_from ActionController::InvalidAuthenticityToken, with: :unprocessable_entity + rescue_from Rack::Timeout::RequestExpiryError, Rack::Timeout::RequestTimeoutError, with: :request_timeout before_action :store_current_location, except: :raise_not_found, unless: :devise_controller? before_action :set_locale @@ -69,6 +70,13 @@ class ApplicationController < ActionController::Base end end + def request_timeout + respond_to do |format| + format.any { head 503 } + format.html { render 'errors/503', layout: 'error', status: 503 } + end + end + def current_account @current_account ||= current_user.try(:account) end diff --git a/app/views/errors/503.html.haml b/app/views/errors/503.html.haml new file mode 100644 index 000000000..f88d50d36 --- /dev/null +++ b/app/views/errors/503.html.haml @@ -0,0 +1,5 @@ +- content_for :page_title do + Request timeout + +- content_for :content do + It took too long to process your request. This might be a temporary server issue diff --git a/config/initializers/timeout.rb b/config/initializers/timeout.rb index 06a29492e..de87fd906 100644 --- a/config/initializers/timeout.rb +++ b/config/initializers/timeout.rb @@ -1,4 +1,6 @@ +Rack::Timeout::Logger.disable +Rack::Timeout.service_timeout = false + if Rails.env.production? Rack::Timeout.service_timeout = 90 - Rack::Timeout::Logger.disable end |