Custom handling of errors

14 views
Skip to first unread message

Lars Olsson

unread,
Jul 15, 2009, 7:25:32 AM7/15/09
to Ramaze
Hi list,

in the old days (before Innate) there was this "magic" action called
"error" that you could use to do custom error handling in your
controllers whenever an exception occured. With Innate this
possibility seem to be missing. There is a new method for catching
whenever an action is missing (Innate::Node#action_missing) but how do
you customize the handling of other exceptions?

I guess it's possible to wrap every action in a begin/rescue block,
but it feels a bit unintuitive.

def foo()
begin
# Do stuff that throws exceptions
rescue StandardError => err
@session[:error] = err
try_resolve(rs(:error))
end
end

def error()
# Do stuff based on @session[:error]
@session.delete[:error]
end

Is there a better way to do custom error handling in the Innate-based
Ramaze?

/lasso

Lars Olsson

unread,
Jul 16, 2009, 10:31:36 AM7/16/09
to Ramaze
Ok, found it. Different kind of exceptions can be be redirected by
Rack::RouteExceptions.route, for instance:

Rack::RouteExceptions.route(Exception, MyController.r(:error))

will route all exceptions to the error action.

Now I just need to figure out how to pass the exception to different
controllers depending on where the error occured. Any ideas?

/lasso

kez

unread,
Jul 16, 2009, 12:28:01 PM7/16/09
to Ramaze
Lars - thanks for posting your findings, this has been something
that's been puzzling me for a few days. Will tie in nicely with :dev
and :live options.

kez.
Reply all
Reply to author
Forward
0 new messages