|
View:
New views
7 Messages
—
Rating Filter:
Alert me
|
|
|
Custom error handlinghi ,guys, referring to http://search.cpan.org/~hkclark/Catalyst-Manual-5.8000/lib/Catalyst/Manual/Cookbook.pod#Delivering_a_Custom_Error_Page, i can't seem to see the error page when I have my Root.pm's sub end set up this way. sub end : ActionClass('RenderView') { my ($self, $c) = @_; $c->log->debug(" Calling END in Root "); if ( scalar @{ $c->error } ) { $c->stash->{errors} = $c->error; $c->stash->{template} = 'menu.tt'; $c->error(0); } else { $c->log->debug(" nothign done "); } } I can see that a $c->error () is being called in one of my controllers and the Room->end has been called (thanks to my debugging messages above) BUT the $c->error doesn't seem to be detected in the Room->end that I have. Instead, i see "nothign done" being printed out. Any ideas , fellas? thank you:) K. akimoto _______________________________________________ List: Catalyst@... Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@.../ Dev site: http://dev.catalyst.perl.org/ |
|
|
Re: Custom error handlingOn 3 Jul 2009, at 08:33, kakimoto@... wrote: > > I can see that a $c->error () is being called in one of my controllers You mean you're calling $c->error yourself in your own controller code? > and the Room->end has been called (thanks to my debugging messages > above) BUT the $c->error doesn't seem to be detected in the Room->end > that I have. Instead, i see "nothign done" being printed out. You haven't shown us the code you're putting stuff into $c->error with, therefore it's pretty hard to tell how you're doing it wrong. Try just putting: die("An error") into your controller code, and you should see that captured in $c- >error when it gets to your end action Cheers t0m _______________________________________________ List: Catalyst@... Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@.../ Dev site: http://dev.catalyst.perl.org/ |
|
|
Re: Custom error handlinghello, Tomas, thank you :) My replies are as per below. > You mean you're calling $c->error yourself in your own controller > code? Yes I am. > You haven't shown us the code you're putting stuff into $c->error > with, therefore it's pretty hard to tell how you're doing it wrong. ---- Extract from Controller (Start) ---- sub _save_address { }; if ($@) { $c->log->debug('Exception while saving address - '. $@); $c->error( q{ An error has occured with the address entered. Please ensure } . q{that you have entered a valid address. If this persists, } . q{please contact our helpdesk at helpdesk@....} ); } return $address->id; } ---- Extract from Controller (End) ---- > > Try just putting: > > die("An error") > > into your controller code, and you should see that captured in $c- > >error when it gets to your end action > yes, when i did that in my controller code, this is what I saw on the terminal's logs: [error] Caught exception in myApp::Controller::Listings->_save_address "An error at /home/kakimoto/projects/myApp/script/../lib/myApp/Controller/Listings.pm line 590." When I remove "-Debug" from myApp.pm, I get just the generic screen saying "Please come back later" whilst when I have "-Debug" there in myApp.pm, I get a screen with the following message in the web browser. "Caught exception in myApp::Controller::Listings->_save_address "An error at /home/kakimoto/projects/myApp/script/../lib/myApp/Controller/Listings.pm line 590." My Root->end now looks like this: sub end : ActionClass('RenderView') { my ($self, $c) = @_; $c->log->debug(" Calling END in Root " #. Data::Dumper->Dump([$c->error]) ); if ( scalar @{ $c->error } ) { $c->log->debug(' Found an error in Root' ); $c->stash->{errors} = $c->error; $c->stash->{template} = 'menu.tt'; } else { $c->log->debug(" nothing done "); } return 1; } In the terminal logs, I do get the message, "Found an error in Root" BUT it doesn't load the template i specified (menu.tt2). Any idea of how to get a custom screen up? _______________________________________________ List: Catalyst@... Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@.../ Dev site: http://dev.catalyst.perl.org/ |
|
|
Re: Custom error handlingOn 5 Jul 2009, at 05:32, kakimoto@... 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@... Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@.../ Dev site: http://dev.catalyst.perl.org/ |
|
|
Re: Custom error handlinghello 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@...> wrote: > > On 5 Jul 2009, at 05:32, kakimoto@... 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@... > Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst > Searchable archive: > http://www.mail-archive.com/catalyst@.../ > Dev site: http://dev.catalyst.perl.org/ > > > _______________________________________________ List: Catalyst@... Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@.../ Dev site: http://dev.catalyst.perl.org/ |
|
|
Re: Custom error handlingOn 6 Jul 2009, at 02:56, kakimoto@... wrote: > > 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? No, what you're doing is fine and supported, but I generally arrange to throw exception objects (instead of strings). These don't get in any way mangled by Catalyst, allowing you to fiddle with them in end to do things such as internationalizing them, or serializing them in API interfaces, and also means that I have less flow control to deal with in exceptional cases.. But throwing strings around is however a perfectly valid technique. Cheers t0m _______________________________________________ List: Catalyst@... Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@.../ Dev site: http://dev.catalyst.perl.org/ |
|
|
Re: Custom error handlinghello Tomas,
thank you. I will look into fine tuning it in the future. Will read more. K. akimoto > > But throwing strings around is however a perfectly valid technique. > _______________________________________________ List: Catalyst@... Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@.../ Dev site: http://dev.catalyst.perl.org/ |
| Free embeddable forum powered by Nabble | Forum Help |