lib/jeanine/app.rb in jeanine-0.1.0 vs lib/jeanine/app.rb in jeanine-0.2.0

- old
+ new

@@ -1,20 +1,24 @@ require 'jeanine/callbacks' require 'jeanine/mimes' require 'jeanine/request' +require 'jeanine/rescuing' require 'jeanine/response' require 'jeanine/renderer' require 'jeanine/routing' +require 'jeanine/session' module Jeanine class App + include Session include Routing::Evaluation attr_reader :request, :response + class << self - include Routing::DSL include Callbacks - + include Routing::DSL + include Rescuing alias :_new :new def new(*args, &block) initialize! stack.run _new(*args, &block) stack @@ -35,14 +39,27 @@ def call(env) new.call env end end + include Rescuing + def call(env) - @env = env - @request = Jeanine::Request.new(env) - @response = Jeanine::Response.new - catch(:halt) { route_eval } + begin + @env = env + @request = Jeanine::Request.new(env) + @response = Jeanine::Response.new + catch(:halt) { route_eval } + rescue => error + handler = self.class.rescue_handlers[error.class] + raise error unless handler + if handler.is_a?(Symbol) + @response.write(send(handler, error)) + else + @response.write(instance_exec(error, &handler)) + end + @response.complete! + end end private def params