module Rack # Returns a user-friendly exception page. # Should be included at the very top of the middleware pipeline so that unhandled # exceptions from anywhere down the pipeline are rescued. # In development, you'd want to use the developer-friendly Rack::ShowExceptions instead. # # config.ru example: # # if ENV['RACK_ENV'] == 'development' # use Rack::ShowExceptions # else # use Rack::PublicExceptionPage # end # # The default HTML included here is a copy of the 500 page included with Rails # You can optionally specify your own file, ex: # # use Rack::PublicExceptionPage, "public/500.html" class PublicExceptionPage def initialize(app, file_path = nil) @app = app @file_path = file_path end def call(env) @app.call(env) rescue ::Exception [500, {'Content-Type' => 'text/html', 'Content-Length' => html.length.to_s}, [html]] end private def html @html ||= @file_path ? ::File.read(@file_path) : default_html end # Exception page from Rails (500.html) def default_html <<-EOV We're sorry, but something went wrong (500)

We're sorry, but something went wrong.

We've been notified about this issue and we'll take a look at it shortly.

EOV end end end