On 10 Dec 2007, at 14:44, Angel Kolev wrote:

sub auto : Private {
  my ($self, $c) = @_;
  if (@{$c->error}) {
$c->stash->{error} = " Critical ERROR!! Probably missing data in database.";
      $c->forward('/error');
      $c->error(0);
      return 0;
  }
}

This dont work. @{$c->error} or scalar @{$c->error} always print 0 in my debug screen.

Felix Antonius Wilhelm Ostmann wrote:
$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.


http://search.cpan.org/~mramberg/Catalyst-Runtime-5.7011/lib/Catalyst.pm#$c-%3Efinalize_error

You need to create a sub finalize_error in your MyApp.pm to catch errors. auto will happen before any errors take place, so of course it will have nothing in it.

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

Something like that anyway - untested.

_______________________________________________
List: [email protected]
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/

Reply via email to