[Catalyst] Custom error
Brian Kirkbride
brian.kirkbride at deeperbydesign.com
Tue Jun 26 17:45:30 GMT 2007
Jason Kohles wrote:
> On Jun 25, 2007, at 1:27 PM, Evaldas Imbrasas wrote:
>
>> Yes, that's what I meant, thanks Brian. Please provide a code example
>> using RenderView action. I think it would also make sense to
>> incorporate that example into the Catalyst cookbook instead of
>> existing one since that one's incomplete.
>
> Something like this...
>
> sub render : ActionClass('RenderView') { }
>
> sub end : Private {
> my ( $self, $c ) = @_;
>
> $c->forward( 'render' );
>
> if ( my @errors = @{ $c->errors } ) {
> $c->response->content_type( 'text/html' );
> $c->response->status( 500 );
> $c->response->body( qq{
> <html>
> <head>
> <title>Error!</title>
> </head>
> <body>
> <h1>Oh no! An Error!</h1>
> } . ( map { "<p>$_</p>" } @errors ) . qq{
> </body>
> </html>
> } );
> }
> }
>
Or even this:
sub render : ActionClass('RenderView') {}
sub end : Private {
my ($self,$c) = @_;
$c->forward('render');
if (my @errors = @{$c->errors}) {
$c->errors(0);
$c->stash->{template} = 'error.tt';
$c->stash->{errors} = \@errors;
$c->forward($c->view('TT'));
}
}
To allow for a templated error page.
Best,
Brian
More information about the Catalyst
mailing list