I would like to run a Rack application, that can be buggy, and
sometimes throws an exception. I want to catch it, and force
my whole Rack app to continue running. This is the schema:
app = …a Rack app definition goes here…
require ‘rack’
begin
Rack::Handler::FastCGI.run app, :Port => 9811
rescue Exception => e
$stderr.puts “…print info about the exception #{e}…”
retry
end
This way I can catch the exception, but when the retry is reached the
Rack::Handler::FastCGI line again, it fails because of the port 9811
is already in use.
How can I close that port (stop Rack server thread?), and tell Rack
to reopen it?
Rack::Handler::FastCGI.run app, :Port => 9811
to reopen it?
I don’ t know Rack but why not just wrap app in something which
delgates to app, catches exceptions and retries?
Hi,
I would like to run a Rack application, that can be buggy, and
sometimes throws an exception.
Hey,
you can define a piece of middleware (something that gets run before
and/or after the request hits the main application easily in Rack, and
I’ve
attached a file that shows how that’s done to handle an error, output
the error message to the console and move on.
Hope it helps,
-Luke
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.