[cgiapp] Graceful Error Handling in CGI::App (compile / init stages)
Michael Peters
mpeters at plusthree.com
Wed Jul 7 09:43:39 EDT 2010
On 07/07/2010 05:16 AM, Mike Tonks wrote:
> 1) So and so CPAN module is not found
>
> 2) Config file not found (ConfigAuto - in cgiapp_init)
>
> currently these produce an ugly 500 Server Error and loeave you
> searching in the apache log for the problem.
>
> For 1) is there a better way than:
>
> use Data::Dumper;
> use XML::Simple;
> use Date::Manip;
> use HTML::FromText;
It's verbose, but the only thing I know of is:
BEGIN {
eval { require Data::Dumper; Data::Dumper::import() };
die "Can't find Data::Dumper module: $@" if $@;
}
repeated for each one.
> that will safely try to load the modules needed and allow me to report
> via a nice formatted error page what's wrong?
Btw, it's not a good idea to show detailed error messages on your
website. It's a security concern as it gives out more information to
attackers than necessary. So it's not a good idea to start.
Error logs are your friend. Learn them and learn to love them.
> 2) If I hit an error in cgiapp_init, is there a way to redirect to an
> error page, as per prerun_mode() ?
There doesn't appear to be. There's the error_mode() but that only seems
to work for run modes, not other stages.
--
Michael Peters
Plus Three, LP
More information about the cgiapp
mailing list