How to show errors that occur in the Sinatra modular application, which is posted by the Passenger?

I have an application class

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

and config.ru file

 # ... load libraries ... run MyApplication 

I usually use Passenger as my development environment, which works great for a regular - non-modular - Sinatra application. But in this case, I don’t have error output, instead I get a page with the default internal server, which doesn’t help much. Is there a way to enable default error handling?

+4
source share
3 answers

I was very worried about the same problem for a long time and just realized a magic spell to return the default error handling. It turns out that this has nothing to do with Passenger, but instead uses Sinatra :: Base instead of the classic (top-level) application. If you subclass Sinatra :: Base, many parameters have different default values. In this case, you must change the parameter:

 set :show_exceptions, true if development? 

If you also want to re-enable the (related) ability to use the error handler in the application, use:

 set :raise_errors, false 

That allows the error do ... end block to work as in a classic application.

For more information about the differences between the classic and Sinatra :: Base applications, see this lighthouse ticket and there is some discussion of this specific difference in the google group .

+4
source

You can 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 
+1
source

Look in the error log of your web server.

-3
source

Source: https://habr.com/ru/post/1299490/


All Articles