Monday, June 8, 2009

Getting Sinatra to Call Your Defined Error Handling Blocks

If you are extending Sinatra::Base, you must set two things to be sure that Sinatra always calls your error handling block like the following example when there is an error:
    error do
      "error: #{request.env['sinatra.error'].to_s}"
    end

The things you must set to be sure that block is called are:

    set :raise_errors, Proc.new { false }
    set :show_exceptions, false

If the first is true, you will get a Rack error in yellow. If the second is true, you'll get the Sinatra error with stuff in red. If both are false, it will call the error handler block.