Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error block not working in Sinatra app

Tags:

sinatra

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)

like image 365
kapso Avatar asked Sep 30 '12 23:09

kapso


2 Answers

You can add:

set :show_exceptions, false

To your application file.

In development environments show_exceptions is enabled by default.

like image 194
Riccardo Marotti Avatar answered Sep 25 '22 00:09

Riccardo Marotti


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

like image 22
Josh Voigts Avatar answered Sep 23 '22 00:09

Josh Voigts