Re: [Catalyst] error handling (Chain where ajax and non-ajax actions chain off)
David == David Schmidt davew...@gmx.at writes: David I tend to put related actions into a controller. E.g.: all actions David dealing with artists into the Artists.pm controller and so on. David You advise (as I understood) means having an additional controller for David every controller where I want to support XHR requests. David Is there a flaw in how I lay out my controllers? Personally, I tend to treat controllers just like any other class, I factor them out when the implementation asks for it. For this case, I think breaking down into separate classes makes sense so you can leverage the catalyst action flow to model your application into layers that get more specific as you drill down the url hierarchy: /artist = calls MyApp::Controller::Root::end() /artist/1 = calls MyApp::Controller::Root::end() /artist/1/xhr = calls MyApp::Controller::Artist::XHR::end() also, since $c-controller (without any arguments) returns the controller of the current dispatched action, you can rely on it to determine the context of the generic actions, for instance, your error handling: $c-detach($c-controller-action_for('error_404')); in Controller::Artist: sub error_404 :Action { my($self, $c) = @_: $c-stash-{template} = 'error_404.tt' } in Controller::Artist::XHR: sub error_404 :Action { my($self, $c) = @_; $self-status_not_found($c, message = 'Cannot find what you were looking for!' ); } -- Eden CardimNeed help with your perl Catalyst or DBIx::Class project? Software Engineer http://www.shadowcat.co.uk/catalyst/ Shadowcat Systems Ltd.Want a managed development or deployment platform? http://blog.edencardim.com http://www.shadowcat.co.uk/servers/ ___ List: Catalyst@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/
Re: [Catalyst] error handling (Chain where ajax and non-ajax actionschain off)
Hi, From: Eden Cardim edencar...@gmail.com in Controller::Artist: sub error_404 :Action { Can I find more information about the :Action dispatch type? Is it just a replacement for :Private? Or it is something different? Thanks. Octavian ___ List: Catalyst@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/
Re: [Catalyst] error handling (Chain where ajax and non-ajax actionschain off)
Octavian, Its just an action with attributes predefie ie: (in your controller): __PACKAGE__-config( action = { myaction = { Chained = 'base', PathPart = q{myaction}, Args = 0, }, }); sub myaction :Action { my ( $self, $c,) = @_; .. } --Hernan 2010/11/10 Octavian Rasnita orasn...@gmail.com Hi, From: Eden Cardim edencar...@gmail.com in Controller::Artist: sub error_404 :Action { Can I find more information about the :Action dispatch type? Is it just a replacement for :Private? Or it is something different? Thanks. Octavian ___ List: Catalyst@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/ ___ List: Catalyst@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/
Re: [Catalyst] error handling (Chain where ajax and non-ajax actionschain off)
Octavian == Octavian Rasnita orasn...@gmail.com writes: Octavian Can I find more information about the :Action dispatch type? Octavian Is it just a replacement for :Private? Or it is something different? Yes, it's effectively a replacement for :Private. -- Eden CardimNeed help with your perl Catalyst or DBIx::Class project? Software Engineer http://www.shadowcat.co.uk/catalyst/ Shadowcat Systems Ltd.Want a managed development or deployment platform? http://blog.edencardim.com http://www.shadowcat.co.uk/servers/ ___ List: Catalyst@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/
[Catalyst] error handling (Chain where ajax and non-ajax actions chain off)
Hello list Both ajax and non-ajax actions chain off the same action (base_with_id). If an error occurs (like the resource doesn't exist) I detach to '/error404' in my Root Controller. I just introduced the ajax stuff and before that 'error404' simply rendered an error template. Now I'd like to check if it is an xmlhttp request using http://search.cpan.org/~flora/Catalyst-TraitFor-Request-XMLHttpRequest-0.01/ and then either render the error template like before OR use the status_not_found() helper from http://search.cpan.org/~bobtfish/Catalyst-Action-REST-0.87/ To use status_not_found I need to extend my Root Controller from Catalyst::Controller::REST That'd mean i have to check the type of request again in my roots end method to avoid rendering of the template. #Root.pm sub render : ActionClass('RenderView') {} sub end :Private { my ($self, $c) = @_; unless ($c-request-is_xhr) { $c-forward('render'); } } Any comments on that solution are appreciated as are pointers to alternatives. david #User.pm sub base : Chained('') PathPart('') CaptureArgs(0) { my ($self, $c ) = @_; $c-stash(users_rs = $c-model('DB::Users')); } sub base_with_id : Chained('base') PathPart('') CaptureArgs(1) { my ($self, $c, $id ) = @_; my $user = $c-stash-{'users_rs'}-find($id); if ($user) { $c-stash(user = $user); } else { $c-stash(error_msg = 'User not found.'); $c-detach('/error404'); } } ___ List: Catalyst@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/
Re: [Catalyst] error handling (Chain where ajax and non-ajax actions chain off)
A bit offtopic but why use the trait at all, you can just check the x-requested-with header for the 'XMLHttpRequest' value - saves you a dependency. As far as the status_not_found routine, I suggest a liberal bit of cut 'n paste and using View::JSON (sort of negates the losing of one dependency if you give up the trait, unless you're using it already). David Schmidt wrote: Hello list Both ajax and non-ajax actions chain off the same action (base_with_id). If an error occurs (like the resource doesn't exist) I detach to '/error404' in my Root Controller. I just introduced the ajax stuff and before that 'error404' simply rendered an error template. Now I'd like to check if it is an xmlhttp request using http://search.cpan.org/~flora/Catalyst-TraitFor-Request-XMLHttpRequest-0.01/ and then either render the error template like before OR use the status_not_found() helper from http://search.cpan.org/~bobtfish/Catalyst-Action-REST-0.87/ -- Ben van Staveren phone: +62 81 70777529 email: benvanstave...@gmail.com ___ List: Catalyst@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/
Re: [Catalyst] error handling (Chain where ajax and non-ajax actions chain off)
David == David Schmidt davew...@gmx.at writes: David Hello list Both ajax and non-ajax actions chain off the same David action (base_with_id). If an error occurs (like the resource David doesn't exist) I detach to '/error404' in my Root Controller. David I just introduced the ajax stuff and before that 'error404' David simply rendered an error template. Now I'd like to check if David it is an xmlhttp request using David http://search.cpan.org/~flora/Catalyst-TraitFor-Request-XMLHttpRequest-0.01/ David and then either render the error template like before OR use David the status_not_found() helper from David http://search.cpan.org/~bobtfish/Catalyst-Action-REST-0.87/ David To use status_not_found I need to extend my Root Controller David from Catalyst::Controller::REST David That'd mean i have to check the type of request again in my David roots end method to avoid rendering of the template. David #Root.pm David sub render : ActionClass('RenderView') {} David sub end :Private { David my ($self, $c) = @_; David unless ($c-request-is_xhr) { David $c-forward('render'); David } David } David Any comments on that solution are appreciated as are pointers David to alternatives. Put the ajax code into a separate controller with an XHR-specific end action (probably empty, for your case) and chain from there. -- Eden CardimNeed help with your perl Catalyst or DBIx::Class project? Software Engineer http://www.shadowcat.co.uk/catalyst/ Shadowcat Systems Ltd.Want a managed development or deployment platform? http://blog.edencardim.com http://www.shadowcat.co.uk/servers/ ___ List: Catalyst@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/
Re: [Catalyst] error handling (Chain where ajax and non-ajax actions chain off)
On Tue, Nov 9, 2010 at 11:38 AM, Eden Cardim edencar...@gmail.com wrote: David == David Schmidt davew...@gmx.at writes: David Hello list Both ajax and non-ajax actions chain off the same David action (base_with_id). If an error occurs (like the resource David doesn't exist) I detach to '/error404' in my Root Controller. David I just introduced the ajax stuff and before that 'error404' David simply rendered an error template. Now I'd like to check if David it is an xmlhttp request using David http://search.cpan.org/~flora/Catalyst-TraitFor-Request-XMLHttpRequest-0.01/ David and then either render the error template like before OR use David the status_not_found() helper from David http://search.cpan.org/~bobtfish/Catalyst-Action-REST-0.87/ David To use status_not_found I need to extend my Root Controller David from Catalyst::Controller::REST David That'd mean i have to check the type of request again in my David roots end method to avoid rendering of the template. David #Root.pm David sub render : ActionClass('RenderView') {} David sub end :Private { David my ($self, $c) = @_; David unless ($c-request-is_xhr) { David $c-forward('render'); David } David } David Any comments on that solution are appreciated as are pointers David to alternatives. Put the ajax code into a separate controller with an XHR-specific end action (probably empty, for your case) and chain from there. I tend to put related actions into a controller. E.g.: all actions dealing with artists into the Artists.pm controller and so on. You advise (as I understood) means having an additional controller for every controller where I want to support XHR requests. Is there a flaw in how I lay out my controllers? david ___ List: Catalyst@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/
[Catalyst] Error handling in Template render
If an exception is thrown it's usually put into the $c-error array. When this error happens during rendering this doesn't seem to be the case and I am trying to find out what Catalyst is doing. In my example forward('render') causes the body to be filled with an error array. This is the body after forward('render') $VAR1 = bless( [ 'undef', bless( { 'msg' = 'Physio::Schema::Result::Exercises::media(): DBI Exception: DBD::Pg::st execute failed: ERROR: column me.mediatype does not exist LINE 1: ..., me.name, me.position, me.file, me.content_type, me.mediaty... ^ [for Statement SELECT me.id, me.exercise_id, me.name, me.position, me.file, me.content_type, me.mediatype, me.created, me.updated FROM media me WHERE ( me.exercise_id = ? ) ORDER BY position with ParamValues: 1=\'1\'] at /home/david/catalyst/Physio/root/templates/exercises/show.tt line 17 ' }, 'DBIx::Class::Exception' ), \' ...' ], 'Template::Exception' ); How do I handle this kind of error? sub end : Private { my ($self, $c) = @_; $c-forward('render'); # display catalyst error page return if $c-debug; # in production log error and display nice error page if (@{$c-error}) { for my $error (@{$c-error}) { $c-log-error($error); } $c-stash(template = 'error.tt'); $c-clear_errors; } } sub render : ActionClass('RenderView') {} ___ List: Catalyst@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/
Re: [Catalyst] Error handling
J. Shirley wrote: That will show you the errors, and I believe get you what you expect to see. Having said all that, I am fond of ErrorCatcher, and use its included Email emitter quite happily. I am currently attempting to use ErrorCatcher to send email but also have a custom error page be rendered. I've tried the Cookbook 'end' method in Root but clearing the error there seems to prevent ErrorCatcher from reacting, but letting it fall through gives me the 'Please come back later' page. Is there a suitable way to have both ErrorCatcher and a custom error page? I'm trying to resist writing an ErrorCatcher emitter just for this. Wes ___ List: Catalyst@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/
Re: [Catalyst] Error handling
On Wed, Jan 20, 2010 at 10:52 AM, Wes Cravens wcrav...@cortex-it.com wrote: J. Shirley wrote: That will show you the errors, and I believe get you what you expect to see. Having said all that, I am fond of ErrorCatcher, and use its included Email emitter quite happily. I am currently attempting to use ErrorCatcher to send email but also have a custom error page be rendered. I've tried the Cookbook 'end' method in Root but clearing the error there seems to prevent ErrorCatcher from reacting, but letting it fall through gives me the 'Please come back later' page. Is there a suitable way to have both ErrorCatcher and a custom error page? I'm trying to resist writing an ErrorCatcher emitter just for this. I am using Catalyst::Plugin::CustomErrorMessage in conjunction with ErrorCatcher -- works like a charm. -J ___ List: Catalyst@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/
Re: [Catalyst] Error handling
On Mon, Jan 18, 2010 at 9:05 AM, Steve Kleiman st...@prodhub.com wrote: Thanks for all the feedback on how to log from within a schema. Log4perl is my hero. I'm still looking for a way to capture runtime errors and ideally email them out in addition to logging to a file. I use log4perl to send error level messages to an additional log file. Then I use cron to check for errors every few minutes and send a notification email. I like that better than the possibility of hundreds of processes cranking out mail at the same time. The plan is to move to a logging server to centralize this a bit more. -- Bill Moseley mose...@hank.org ___ List: Catalyst@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/
Re: [Catalyst] Error handling
Steve Kleiman wrote: Found a post on this mailing list suggesting: sub finalize_error { my ($c) = @_; # Note, not ($self, $c) if ( @{$c-errors} ) { $c-stash-template('error.tt'); # You might also need to forward to the view here yourself return; } $c-NEXT::finalize_error(); } But the error seems to abort all processing and never make it to this point. I don't see why that's happening - can you explain what you mean by 'abort all processing'? The most common reason for custom error handlers not working is that people forget to call $c-clear_error... Cheers t0m ___ List: Catalyst@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/
Re: [Catalyst] Error handling
Thanks for getting back, t0m. By abort all processing it seemed like when the error was thrown, Catalyst stopped processing the request. Here's my fabricated error in a controller: sub test_error : Local { my ( $self, $c ) = @_; Log::Log4perl-get_logger('General')-info('before error'); $c-nonexistent_method; Log::Log4perl-get_logger('General')-info('after error'); $c-response-body('Got past error'); } Thanks to log4perl, I see the request seemingly hits 'end' before the error is registered (see console log below). I also have a log line in 'finalize_error' but it never gets hit. I tried putting '$c-clear_errors' in my 'end' method, but then the error doesn't print to console at all. I'm missing something -steve 2010/01/18 17:33:16 Root.pm 100 auto 2010/01/18 17:33:16 Administration.pm 55 before error 2010/01/18 17:33:16 Root.pm 148 end [info] *** Request 2 (0.002/s) [5404] [Mon Jan 18 17:33:16 2010] *** [debug] GET request for app/project/administration/test_error from 127.0.0.1 [debug] Path is app/project/administration/test_error [debug] Found sessionid a6868e20c5ff9800b88e1a6ac7eef75ec4e9a8c4 in cookie [debug] Restored session a6868e20c5ff9800b88e1a6ac7eef75ec4e9a8c4 [debug] running ACL rule CODE(0x1027c0438) defined at /Users/smk/enola/ProdHub/tech/prodhub/prodhub/script/../lib/Prodhub.pm line 307 on app/project/administration/test_error [debug] Access to app/project/administration/test_error allowed by rule CODE(0x1027c0438) (defined at /Users/smk/enola/ProdHub/tech/prodhub/prodhub/script/../lib/Prodhub.pm line 307) [error] Caught exception in Prodhub::Controller::App::Project::Administration-test_error Can't locate object method nonexistent_method via package Prodhub at /Users/smk/enola/ProdHub/tech/prodhub/prodhub/script/../lib/Prodhub/Controller/App/Project/Administration.pm line 56. [error] Caught exception in engine Can't use string (a6868e20c5ff9800b88e1a6ac7eef75e) as a HASH ref while strict refs in use at /usr/local/lib/perl5/site_perl/5.10.1/Catalyst/Engine.pm line 117. On Jan 18, 2010, at 9:22 AM, Tomas Doran wrote: Steve Kleiman wrote: Found a post on this mailing list suggesting: sub finalize_error { my ($c) = @_; # Note, not ($self, $c) if ( @{$c-errors} ) { $c-stash-template('error.tt'); # You might also need to forward to the view here yourself return; } $c-NEXT::finalize_error(); } But the error seems to abort all processing and never make it to this point. I don't see why that's happening - can you explain what you mean by 'abort all processing'? The most common reason for custom error handlers not working is that people forget to call $c-clear_error... Cheers t0m ___ List: Catalyst@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/
Re: [Catalyst] Error handling
On Mon, Jan 18, 2010 at 5:44 PM, Steve Kleiman st...@prodhub.com wrote: Thanks for getting back, t0m. By abort all processing it seemed like when the error was thrown, Catalyst stopped processing the request. Here's my fabricated error in a controller: sub test_error : Local { my ( $self, $c ) = @_; Log::Log4perl-get_logger('General')-info('before error'); $c-nonexistent_method; Log::Log4perl-get_logger('General')-info('after error'); $c-response-body('Got past error'); } Thanks to log4perl, I see the request seemingly hits 'end' before the error is registered (see console log below). I also have a log line in 'finalize_error' but it never gets hit. I tried putting '$c-clear_errors' in my 'end' method, but then the error doesn't print to console at all. I'm missing something -steve 2010/01/18 17:33:16 Root.pm 100 auto 2010/01/18 17:33:16 Administration.pm 55 before error 2010/01/18 17:33:16 Root.pm 148 end [info] *** Request 2 (0.002/s) [5404] [Mon Jan 18 17:33:16 2010] *** [debug] GET request for app/project/administration/test_error from 127.0.0.1 [debug] Path is app/project/administration/test_error [debug] Found sessionid a6868e20c5ff9800b88e1a6ac7eef75ec4e9a8c4 in cookie [debug] Restored session a6868e20c5ff9800b88e1a6ac7eef75ec4e9a8c4 [debug] running ACL rule CODE(0x1027c0438) defined at /Users/smk/enola/ProdHub/tech/prodhub/prodhub/script/../lib/Prodhub.pm line 307 on app/project/administration/test_error [debug] Access to app/project/administration/test_error allowed by rule CODE(0x1027c0438) (defined at /Users/smk/enola/ProdHub/tech/prodhub/prodhub/script/../lib/Prodhub.pm line 307) [error] Caught exception in Prodhub::Controller::App::Project::Administration-test_error Can't locate object method nonexistent_method via package Prodhub at /Users/smk/enola/ProdHub/tech/prodhub/prodhub/script/../lib/Prodhub/Controller/App/Project/Administration.pm line 56. [error] Caught exception in engine Can't use string (a6868e20c5ff9800b88e1a6ac7eef75e) as a HASH ref while strict refs in use at /usr/local/lib/perl5/site_perl/5.10.1/Catalyst/Engine.pm line 117. Hi Steve, First (and you missed my talk at Perl Oasis where I actually went over this!) to address the original question, I've been using Catalyst::Plugin::ErrorCatcher with great success. Works as expected. You can see more at: http://search.cpan.org/dist/Catalyst-Plugin-ErrorCatcher As for what you are seeing, I'd have to see your end action. If you put clear_errors, nothing will be printed out. Think of that as an eval { } where you throw away $...@. What you can do is: $c-log-_dump( $c-errors ); $c-clear_errors; That will show you the errors, and I believe get you what you expect to see. Having said all that, I am fond of ErrorCatcher, and use its included Email emitter quite happily. Thanks, -J ___ List: Catalyst@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/
[Catalyst] error handling
Hi,all. Can anyone eplain me a bit about error handling. Where i can catch it and when? I use this: MyApp::C::MyController sub auto : Private { my ($self, $c) = @_; if ($c-error) { $c-stash-{error} = Critical ERROR!! ; $c-forward('/error'); $c-error(0); return 0; } } This works but then all my subs in this controller are redirected to /error. ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] error handling
$c-error is a arrayref or not? So you must do this: if( @{$c-error} ) { ... } Angel Kolev schrieb: Hi,all. Can anyone eplain me a bit about error handling. Where i can catch it and when? I use this: MyApp::C::MyController sub auto : Private { my ($self, $c) = @_; if ($c-error) { $c-stash-{error} = Critical ERROR!! ; $c-forward('/error'); $c-error(0); return 0; } } This works but then all my subs in this controller are redirected to /error. ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ Dev site: http://dev.catalyst.perl.org/ -- Mit freundlichen Grüßen Felix Antonius Wilhelm Ostmann -- Websuche Search Technology GmbH Co. KG Martinistraße 3 - D-49080 Osnabrück - Germany Tel.: +49 541 40666-0 - Fax:+49 541 40666-22 Email: [EMAIL PROTECTED] - Website: www.websuche.de -- AG Osnabrück - HRA 200252 - Ust-Ident: DE814737310 Komplementärin: Websuche Search Technology Verwaltungs GmbH - AG Osnabrück - HRB 200359 Geschäftsführer: Diplom Kaufmann Martin Steinkamp -- ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/[EMAIL PROTECTED]/ Dev site: http://dev.catalyst.perl.org/