开发者

How to show errors that occur in a modular Sinatra Application which is hosted by Passenger?

I have an application class

class MyApplication < Sinatra::Base
  # ... do something ...
end

and a config.ru file

# ... load libraries开发者_C百科 ...
run MyApplication

I usually use Passenger as my development environment which works perfectly fine for a normal – non-modular – Sinatra application. But in this case I have no error output instead I get the default internal server error page which isn't very helpful. Is there a way to enable the default error handling?


I've been bothered by this same issue for quite a while and just finally figured out the magic incantation to bring the default error handling back. It turns out it has nothing to do with Passenger, but is instead caused by using Sinatra::Base instead of a classic (top-level) application. If you subclass Sinatra::Base, many of the options have different defaults. In this case, the option you need to change is:

set :show_exceptions, true if development?

If you'd also like to re-enable the (related) ability to use an in-app error handler, use:

set :raise_errors, false

Which allows the error do ... end block to work like it does in a classic app.

Additional information about the differences between the classic and Sinatra::Base apps can be found in this lighthouse ticket and there's some discussion of this specific difference in the google group.


You could use Rack::ShowExceptions to display the stack trace

configure do
  enable :dump_errors,:raise_errors
  use Rack::ShowExceptions
end

and use the Sinatra error handler to display

$exception = Sinatra::ShowExceptions.new(self)
error do 
  @error = env['sinatra_error']
  html_body = $exception.pretty(env,@error)
end


Look in your web server error log.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜