Add proper error page for request timeouts
This commit is contained in:
		
							parent
							
								
									34ff11c496
								
							
						
					
					
						commit
						5b12624847
					
				
							
								
								
									
										2
									
								
								Gemfile
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								Gemfile
									
									
									
									
									
								
							@ -50,6 +50,7 @@ gem 'rails-settings-cached'
 | 
				
			|||||||
gem 'simple-navigation'
 | 
					gem 'simple-navigation'
 | 
				
			||||||
gem 'statsd-instrument'
 | 
					gem 'statsd-instrument'
 | 
				
			||||||
gem 'ruby-oembed', require: 'oembed'
 | 
					gem 'ruby-oembed', require: 'oembed'
 | 
				
			||||||
 | 
					gem 'rack-timeout'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
gem 'react-rails'
 | 
					gem 'react-rails'
 | 
				
			||||||
gem 'browserify-rails'
 | 
					gem 'browserify-rails'
 | 
				
			||||||
@ -89,5 +90,4 @@ group :production do
 | 
				
			|||||||
  gem 'rails_12factor'
 | 
					  gem 'rails_12factor'
 | 
				
			||||||
  gem 'redis-rails'
 | 
					  gem 'redis-rails'
 | 
				
			||||||
  gem 'lograge'
 | 
					  gem 'lograge'
 | 
				
			||||||
  gem 'rack-timeout'
 | 
					 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
				
			|||||||
@ -12,6 +12,7 @@ class ApplicationController < ActionController::Base
 | 
				
			|||||||
  rescue_from ActionController::RoutingError, with: :not_found
 | 
					  rescue_from ActionController::RoutingError, with: :not_found
 | 
				
			||||||
  rescue_from ActiveRecord::RecordNotFound, with: :not_found
 | 
					  rescue_from ActiveRecord::RecordNotFound, with: :not_found
 | 
				
			||||||
  rescue_from ActionController::InvalidAuthenticityToken, with: :unprocessable_entity
 | 
					  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 :store_current_location, except: :raise_not_found, unless: :devise_controller?
 | 
				
			||||||
  before_action :set_locale
 | 
					  before_action :set_locale
 | 
				
			||||||
@ -69,6 +70,13 @@ class ApplicationController < ActionController::Base
 | 
				
			|||||||
    end
 | 
					    end
 | 
				
			||||||
  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
 | 
					  def current_account
 | 
				
			||||||
    @current_account ||= current_user.try(:account)
 | 
					    @current_account ||= current_user.try(:account)
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										5
									
								
								app/views/errors/503.html.haml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								app/views/errors/503.html.haml
									
									
									
									
									
										Normal file
									
								
							@ -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
 | 
				
			||||||
@ -1,4 +1,6 @@
 | 
				
			|||||||
 | 
					Rack::Timeout::Logger.disable
 | 
				
			||||||
 | 
					Rack::Timeout.service_timeout = false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if Rails.env.production?
 | 
					if Rails.env.production?
 | 
				
			||||||
  Rack::Timeout.service_timeout = 90
 | 
					  Rack::Timeout.service_timeout = 90
 | 
				
			||||||
  Rack::Timeout::Logger.disable
 | 
					 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user