[Nitro] nitro error pages

Jonathan Buch john at oxyliquit.de
Wed Dec 6 06:49:14 EST 2006


Hi,

> I would like to improve how nitro handles error pages especially in
> live mode. Anyone has any related ideas suggestions that would like to
> share before I start?

Yes, two slightly unrelated suggestions:

* please write something about caching
* please release 0.41 bugfix release

before putting your mind to new cool stuff.  :)


I think there was a thread on error handling before..

Ah yeah, how it's done in IOWA, very neat and flexible approach:

http://rubyforge.org/pipermail/nitro-general/2006-October/006157.html

This probably would be like a lookup table, if one of the rules
matches the thrown exception.
If it matches, it uses the given (maybe custom) handler.  That handler
would probably have to be given the occured exception.  The handler
might be a class responding to .render_error.

I'm not sure if the error handling has to be so fine-grained that
controllers can own a custom.....
But that certanly could be done quite easily...

render.rb, Nitro::Render#render

rescue Object => ex
   if handler = lookup_error_handler(@controller, ex)
     handler.render_error(ex)
   else
     log_error(e1, path, false)
     print '(error)'
   end
end

def lookup_error_handler(controller, ex)
   if controller has custom error_handler
     controller.get_error_handler(ex)  # custom
   else
     Nitro::Render.get_error_handler(ex) # global `setting`
   end
end

class CustomErrorHandler
   def handles_error?(ex); ex.is_a?(ActionError); end

   def handle_error(ex)
     raise ArgumentError unless handles_error?(ex)
     redirect_to '/argument_error_page.html'
   end
end

class Nitro::Render
   setting :error_handlers, :default =>
        [RenderExit => SwallowErrorHandler]
end

class MyController
   def self.error_handlers
     [ArgumentError => CustomErrorHandler]
   end
end

or something similar along those lines.

I like the idea and it's pretty flexible and easy to implement.
What'cha think?

Jo

-- 
Feel the love
http://pinkjuice.com/pics/ruby.png


More information about the Nitro-general mailing list