perlquestion
dvwright
<p>Howdy,</p>
<p>I have some legacy Perl CGI scripts running under mod_perl.</p>
<code>
SetHandler perl-script
PerlResponseHandler ModPerl::Registry
PerlOptions +ParseHeaders
Options +ExecCGI
</code>
<p>When a application level, Database related Software error occurs,
raw SQL gets output to the browser. Basically the same message as found
in the error_log. (e.g Software error: Can't execute 'SELECT,.. etc)</p>
<p>The access_log does show this as a HTTP 500 error, however setting ErrorDocument within httpd.conf does not catch it)</p>
<p>In the past I have used CGI::Carp qw(fatalsToBrowser) within a script
to catch errors and display a custom message, however in this case
there are enough scripts that it would be preferred if I could just
define a handler or callback somewhere to capture the output and
return the output of my choice. (like how Apache can set ErrorDocument)</p>
<p>I thought maybe I could get at through PerlLogHandler or maybe even
subclassing RegistryCooker but it looks like that won't work.</p>
<p>Ideas? it seems like a simple thing I am overlooking.</p>
<code>Apache/2.2.3
mod_perl/2.0.5
CentOS release 5.5 (Final)</code>
<p>Thanks
</p>
<br/>
<p>UPDATE: Turns out I cant use fatalsToBrowser either, currently I'm looking into this: <a href="http://perl.apache.org/docs/general/perl_reference/perl_reference.html#Alternative%5FException%5FHandling%5FTechniques">$SIG{__DIE__}</a> Thanks</p>
<br/><br/>
<p>FINAL UPDATE with solution:<br/><br/>
Yes, so the whole point is A. not leaking sensitive details to end users and B. 'save face' in front of customers.<br/>
So, the reason why the Apache setting ErrorDocument was not working was because there is also a reverse proxy running. To enable:
<code>
ProxyErrorOverride On
</code><br/>
Another approach is to write your own PerlResponseHandler (see ModPerl::Registry, basically you subclass ModPerl::RegistryCooker.
<code>
my $old_status = $my_rc->{REQ}->status;
my $rc = $my_rc->run;
if ($rc == 500){ # 500 error occured
</code>
</p>