[Catalyst] Catching errors in end

Sebastian Riedel sri at oook.de
Sat Dec 10 19:15:37 CET 2005


Am 10.12.2005 um 17:13 schrieb Bill Moseley:

> I suspect I'm trying to do this the had way.  I want to handle errors
> and display my own error template.
>
> sub end : Global {
>     my ($self, $c) = @_;
>
>     return if $c->res->status == 304;
>
>     if ( @{$c->error} ) {
>         $c->log->error($_) for @{$c->error};
>         $c->res->status( 500 );
>         $c->error(0);
>     }
>
>     $c->stash->{template} = 'error.tt' unless $c->res->status == 200;
>     $c->forward('App::V::TT') unless $c->res->body;
>
> }
>
> But that doesn't work if the error happens in the template, so after
> calling TT I added:
>
>     # Catch errors in the template
>
>     if ( @{$c->error} ) {
>         $c->res->status( 500 );
>         $c->error(0);
>         $c->stash->{template} = 'error.tt';
>         $c->forward('App::V::TT');
>     }
> }
>
> Which seems a bit redundant.  Is there a better (single) place to
> catch both those?  Override finalize_error instead?  Or maybe just a
> better approach?

You have to be redundant in this case, i don't see a reason to  
overload finalize_error.


--
sebastian




More information about the Catalyst mailing list