[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [cgiapp] CGI Error handling


Quoting Mark Fuller <suppressed>:

> What's a good way to abort normal processing and display a simple error
> message?
> 

> What I'd like to have is some way to abort the run-mode method, in
> mid-stream, and let another one take over. Is there any way to do this?

Inside your runmode just return the results of another runmode...  Here is some
pseudocode

sub my_runmode {
  my $self = shift;

  if (mysql_call_failed) {
    return $self->error_runmode($mysql_error_message);
  }

  ...
}

sub error_runmode {
  my $self = shift;
  my @errors = @_;

  my $template = new HTML::Template(filename => 'error.tmpl');

  $template->param(errors => suppressed);
  return $template->output()
}


}

The only problem with this approach is if the error.tmpl file can not be found,
or contains an error...  You could instead switch back to the old method of just
manually creating the HTML in the code (just for the error runmode) to make sure
you never get an error inside that runmode.

> Also, similar topic. I tried using prerun_mode() to set my start-mode. Log
> messages began appearing in my server error-log saying the start_mode was
> changed. Is there a way to tell it I expected the mode to change and
> therefore don't want to see error-log entries about it?

Currently you have to turn off warnings in order to do that.  You might be able
to turn off the warnings locally to that subroutine, but I think it is something
that should probably be changed in CGI::Application.  ie it could have a config
option to turn on/off warnings.

Cheers,

Cees

---------------------------------------------------------------------
Web Archive:  http://www.mail-archive.com/suppressed/
              http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: suppressed
For additional commands, e-mail: suppressed


Mail converted by mhonarc 2.6.15
This archive provided courtesy of JSW4.NET, Internet Hosting Services for Small Business.