[Catalyst] Error handling strategy wrt /end

Bill Moseley moseley at hank.org
Fri Jan 27 01:04:03 CET 2006


On Thu, Jan 26, 2006 at 02:43:48PM -0800, Phil Mitchell wrote:
> Curious to know how other people approach error handling.


I'm not that thrilled with mine, but in my application end I do:



    return if $c->res->status == 304;

    if ( @{$c->error} ) {
        $c->log->error($_) for @{$c->error};
        $c->res->status( 500 );
        $c->error(0);

        if ( $c->is_ajax ) {
            $c->stash->{json} = { error => 'Error processing request' };
            return $c->forward('App::V::JSON');
        }
    }


    # On some errors allow custom error document
    $c->stash->{template} = 'error.tt' unless $c->res->status == 200;

    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');
    }

and if that second call to the view dies then I get the catalyst
default error page.



-- 
Bill Moseley
moseley at hank.org




More information about the Catalyst mailing list