On Fri, Apr 25, 2008 at 3:15 AM, Daniel Fetchinson
<[EMAIL PROTECTED]> wrote:
>
>  Hi folks,
>
>  I've tried passing a function as argument to @error_handler but it
>  doesn't seem to work. Is it possible at all? Or the argument has to be
>  a method? This is what I tried:
>
>  def error( dummy, tg_errors=None ):
>     return dict( errors=tg_errors, success=False, msg='There was an error' )
>
>  class controller( turbogears.controllers.Controller ):
>     @expose( )
>     @error_handler( error )
>     @validate( validators=dict( value=Int( ) ) )
>     def hello( self, value=2 ):
>         return dict( value=value )
>
>  The first argument, 'dummy', of error( ) serves as the placeholder for
>  the instance that is normally passed as first argument to a method.
>  The reason I go this way is that I'd like to have the same
>  error_handler for all methods of several controllers and want to
>  define this error_handler only once. If I define it as a method on one
>  of the controllers I can't really pass it to @error_handler decorating
>  another method in another controller, can I?

the correct way will be to define the generic error handler in the
root controller. in TG2 this will be a lot easier as you can edit your
rootcontroller in your /lib.
in tg1 it's a bit more complicated you will do something like this.
remember they are objects.

class myRootController(RootController):
    @expose()
   def errorHandler(......)
        ......

class Controller1(myRootController):
    etc.

class Controller2(myRootController):
    etc.


that way you have one definition of the error handler and it's
inherited to all of them.
>
>  It might easily be that I'm overcomplicating something in which case
>  I'd be curious to know how you guys would deal with this situation.
>
>  Cheers,
>  Daniel
>
>  >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to