[Catalyst] Custom error handling
kakimoto at tpg.com.au
kakimoto at tpg.com.au
Mon Jul 6 01:56:50 GMT 2009
hello Tomas and everyone,
Thank you for that.
I got it working.
What I also did was the in the case of an exception, I will redirect
the user back to the main page with the error shown.
I would like to share what I did.
On Root.pm->end: I passed the error message to the flash (I have
flash_to_stash turned on) because due to a redirection, the only way the
error message can be sustained is via the flash.
============
sub end : ActionClass('RenderView') {
my ($self, $c) = @_;
if ( scalar @{ $c->error } ) {
$c->flash->{errors} = $c->error;
$c->response->redirect($c->uri_for('/'));
$c->error(0);
}
return 1;
};
On my controller, Subscriptions.pm
=======================
sub _save_address : Private
{
eval
{
.....
};
if ($@)
{
$c->error (' A problem occurred when saving your address.
Please try again later' );
}
}
Using die(' A problem occurred when saving your address. Please try
again later' );,
I would get an error message such as "Exception caught in
myApp::Controller::Subscription->_save_address" which doesn't look so
good to the users.
that's why I used $c->error.
Please tell me if it's bad practice?
thank you, everybody for your time! :)
K. akimoto
On Mon, Jul 6th, 2009 at 12:22 AM, Tomas Doran <bobtfish at bobtfish.net>
wrote:
>
> On 5 Jul 2009, at 05:32, kakimoto at tpg.com.au wrote:
> > Any idea of how to get a custom screen up?
>
> You're not clearing the errors, so Catalyst gives you an error
> screen:
>
> http://search.cpan.org/~flora/Catalyst-Runtime-5.80007/lib/
> Catalyst.pm#$c-%3Eclear_errors
>
> Cheers
> t0m
>
>
> _______________________________________________
> List: Catalyst at lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive:
> http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/
>
>
>
More information about the Catalyst
mailing list