[Catalyst] Error handling strategy wrt /end

Phil Mitchell phil at 2people.org
Sat Jan 28 02:09:15 CET 2006


On 1/26/06, Bill Moseley <moseley at hank.org> wrote:
>
>
>     eval { $c->forward('App::V::TT') unless $c->res->body; };
>
>     # Catch errors in the template
>     # Of course, might not be able to generate templates....
>
>     if ( @{$c->error} ) {
>         # Already printed???
>         #$c->log->error($_) for @{$c->error};
>         $c->res->status( 500 );
>         $c->error(0);
>         $c->stash->{template} = 'error.tt';
>         $c->forward('App::V::TT');
>     }


Interesting... why do you use an eval block here? I assumed it would let me
trap exceptions, but since catalyst already traps them, it actually doesn't.
I find that a bit counterintuitive, but I don't know if there's a better way
for catalyst to do it. Here's what I wound up doing:

        $c->forward('Reef::V::TT');
        # If the view fails, try it again with error template
        if ( @{$c->error} ) {
           my $msg = q{There's been an unexpected error. } .
                      q{Please try again or report the problem.};
           $c->reef_log(error => $_) for @{$c->error};
           $c->res->status(500);
           $c->reef_set_message($msg);
           $c->error(0);
           $c->stash->{template} = $C->TT_ERROR;
           $c->forward('Reef::V::TT');
           # If it fails again, redirect to static error page
           if ( @{$c->error} ) {
              $c->reef_log(error => $_) for @{$c->error};
              $c->res->status(500);
              $c->error(0);
              $c->res->redirect($C->STATIC_ERROR_PAGE);
           }
        } # end error handling

Works well. Thanks again .. I learned some things from your code!

--
==========================
2People Blog: http://2-people.blogspot.com/
2People site: http://www.2people.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.rawmode.org/pipermail/catalyst/attachments/20060127/eabfc975/attachment.htm


More information about the Catalyst mailing list