Search code examples
rubyerror-handlingsinatrainternal-server-error

How to override default Internal Server Error in Ruby/Sinatra to display erb file


I want to override the normal sinatra internal server error so it instead displays an erb file.

So far I have this:

set :show_exceptions, :after_handler
error 400..510 do
  erb :error
end

But it doesn't work... any ideas?


Solution

  • This is most probably because you run it in the development mode. Not sure if you can suppress it there. But since most time it's only important to show this error pages in production you can simply set RACK_ENV to production.

    For example if you start your app like this:

    bundle exec ruby app.rb

    Just add RACK_ENV

    RACK_ENV=production bundle exec ruby app.rb

    Most times on a Production server this is set anyway, so there is no need to set it explicit.