kapso
kapso

Reputation: 11903

Error block not working in Sinatra app

I have the following Sinatra app and I am testing the error block but it doesnt seem to be working.

Here's my sinatra app:

require 'rubygems'
require 'sinatra'

error do
  puts "----> Failed"
  $stdout.print "----> Failed"
end

get "/*" do
  raise "Error!!"
end

I am using sinatra (1.3.3)

Upvotes: 5

Views: 1154

Answers (3)

sai
sai

Reputation: 396

make sure you are not using the beta version of rack

gem list rack

if you see something like the following:

rack-1.6.0.beta

Uninstall this version and use the previous version rack-1.5.2

Upvotes: 0

Riccardo Marotti
Riccardo Marotti

Reputation: 20348

You can add:

set :show_exceptions, false

To your application file.

In development environments show_exceptions is enabled by default.

Upvotes: 6

Josh Voigts
Josh Voigts

Reputation: 4132

Sinatra uses its own error handler when it is set in development mode, which it is by default. For your error to show up you have to run your app in production mode like this:

ruby my_app.rb -e production

Here's a link to the specific documentation for further reference: Sinatra README #Environments

Upvotes: 4

Related Questions