setting one common error_handler, instead of one per controller

25 views
Skip to first unread message

alex bodnaru

unread,
Aug 1, 2012, 3:15:22 AM8/1/12
to turbo...@googlegroups.com

hello friends,

in my project, i'd like to use only one common error_handler, instead of one for
each controller.
how would you do that?

thanks in advance,
alex

Michael Pedersen

unread,
Aug 2, 2012, 11:27:12 AM8/2/12
to turbo...@googlegroups.com
I don't believe we have such a facility. While it might be possible to do, I'm not even sure that's desirable. What are you trying to accomplish? More importantly, why? We may need to do something for this.


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




--
Michael J. Pedersen
My Online Resume: http://www.icelus.org/ -- Google+ http://plus.ly/pedersen
Google Talk: m.ped...@icelus.org -- Twitter: pedersentg

alex bodnaru

unread,
Aug 2, 2012, 3:58:11 PM8/2/12
to turbo...@googlegroups.com

hello michael,

On 08/02/2012 06:27 PM, Michael Pedersen wrote:
> I don't believe we have such a facility. While it might be possible to do, I'm
> not even sure that's desirable. What are you trying to accomplish? More
> importantly, why? We may need to do something for this.
>
all my controllers inherit basecontroller.
i'd like most @validate error_handlers to behave the same. hence i'd put this
error_handler in base.
how would you do it?

thanks in advance,
alex

> On Wed, Aug 1, 2012 at 3:15 AM, alex bodnaru <alexbod...@gmail.com
> <mailto:alexbod...@gmail.com>> wrote:
>
>
> hello friends,
>
> in my project, i'd like to use only one common error_handler, instead of one for
> each controller.
> how would you do that?
>
> thanks in advance,
> alex
>
> --
> You received this message because you are subscribed to the Google Groups
> "TurboGears" group.
> To post to this group, send email to turbo...@googlegroups.com
> <mailto:turbo...@googlegroups.com>.
> To unsubscribe from this group, send email to
> turbogears+...@googlegroups.com
> <mailto:turbogears%2Bunsu...@googlegroups.com>.
> For more options, visit this group at
> http://groups.google.com/group/turbogears?hl=en.
>
>
>
>
> --
> Michael J. Pedersen
> My Online Resume: http://www.icelus.org/ -- Google+ http://plus.ly/pedersen
> Google Talk: m.ped...@icelus.org <mailto:m.ped...@icelus.org> -- Twitter:
> pedersentg

Michael Pedersen

unread,
Aug 2, 2012, 5:56:29 PM8/2/12
to turbo...@googlegroups.com
On Thu, Aug 2, 2012 at 3:58 PM, alex bodnaru <alexbod...@gmail.com> wrote:

hello michael,

On 08/02/2012 06:27 PM, Michael Pedersen wrote:
> I don't believe we have such a facility. While it might be possible to do, I'm
> not even sure that's desirable. What are you trying to accomplish? More
> importantly, why? We may need to do something for this.
>
all my controllers inherit basecontroller.
i'd like most @validate error_handlers to behave the same. hence i'd put this
error_handler in base.
how would you do it?

I wouldn't. @validate is on a per method basis because each method is expecting something different. I have no idea of any use case where a number of methods are expecting everything to be the same. As a result, I can't conceive of a time that I would even *try* to do what you're describing, never mind actually doing it.
 
--
Michael J. Pedersen
My Online Resume: http://www.icelus.org/ -- Google+ http://plus.ly/pedersen
Google Talk: m.ped...@icelus.org -- Twitter: pedersentg

alex bodnaru

unread,
Aug 4, 2012, 7:59:30 AM8/4/12
to turbo...@googlegroups.com

hello michael,

On 08/03/2012 12:56 AM, Michael Pedersen wrote:
> On Thu, Aug 2, 2012 at 3:58 PM, alex bodnaru <alexbod...@gmail.com
> <mailto:alexbod...@gmail.com>> wrote:
>
>
> hello michael,
>
> On 08/02/2012 06:27 PM, Michael Pedersen wrote:
> > I don't believe we have such a facility. While it might be possible to do, I'm
> > not even sure that's desirable. What are you trying to accomplish? More
> > importantly, why? We may need to do something for this.
> >
> all my controllers inherit basecontroller.
> i'd like most @validate error_handlers to behave the same. hence i'd put this
> error_handler in base.
> how would you do it?
>
>
> I wouldn't. @validate is on a per method basis because each method is expecting
> something different. I have no idea of any use case where a number of methods
> are expecting everything to be the same. As a result, I can't conceive of a time
> that I would even *try* to do what you're describing, never mind actually doing it.

all i wanted is to save the tmpl_context.form_errors in the request object, and
raise an exception. this would better be done from basecontroller.
this exception would later trigger /error/document, which i've patched to
display this error.
since this is a quite routine job, won't this be something to do in only one place?

best regards,
alex
>
> --
> Michael J. Pedersen
> My Online Resume: http://www.icelus.org/ -- Google+ http://plus.ly/pedersen

Michael Pedersen

unread,
Aug 5, 2012, 2:02:31 PM8/5/12
to turbo...@googlegroups.com
On Sat, Aug 4, 2012 at 7:59 AM, alex bodnaru <alexbod...@gmail.com> wrote:
all i wanted is to save the tmpl_context.form_errors in the request object, and
raise an exception. this would better be done from basecontroller.
this exception would later trigger /error/document, which i've patched to
display this error.
since this is a quite routine job, won't this be something to do in only one place?

Okay, that makes sense, and now I have an answer for how I would do it:

In BaseController, add the following code in the __call__ method:

if hasattr(tmpl_context, 'form_errors'):
    request.form_errors = templ_context.form_errors
    raise Exception('change to your exception here')
 
--
Michael J. Pedersen
My Online Resume: http://www.icelus.org/ -- Google+ http://plus.ly/pedersen
Google Talk: m.ped...@icelus.org -- Twitter: pedersentg

Reply all
Reply to author
Forward
0 new messages