I want to handle ErrorDocuments with a mod_perl module Apache::MyError in a way that the actual error message (server error 500, as written to the logs) is displayed within the result HTML page.

I know that this is evil, just treat it as an academic approach. (What I want to do in real life is mail the message to the webmaster and display a backtrace id to the user referring to that error)

What I have so far is my httpd.conf,

ErrorDocument 500 /errors/500 <Location /errors> SetHandler perl-script PerlHandler Apache::MyError Options +ExecCGI PerlSendHeader On </Location>

a script that won't compile under /usr/local/apache/cgi-bin/die.pl and the following:

package Apache::Error; use strict; use Apache::Constants qw(:common); sub handler { my $r = Apache->request; my $p = $r->prev; $r->status(OK); $r->content_type("text/html"); $r->send_http_header; $r->print("<pre>\n"); $r->print($r->path_info, "\n"); $r->print($p->notes("error-notes"), "\n"); $r->print("</pre>\n"); return OK; } 1;

The log says:

syntax error at /usr/local/apache/cgi-bin/die.pl line 6, near "if {" Missing right curly or square bracket at /usr/local/apache/cgi-bin/die +.pl line 8, at end of line Execution of /usr/local/apache/cgi-bin/die.pl aborted due to compilati +on errors. [Mon Sep 30 13:42:51 2002] [error] [client xxx.xxx.xxx.xxx] Premature +end of script headers: /usr/local/apache/cgi-bin/die.pl

$p->notes("error-notes") contains "premature end of ..." but not the "syntax error ..." which is the one I want to have.

Can someone guide me to a solution (I know one from mod_ruby using the method error_message)? Am I missing something?

alex pleiner <alex@zeitform.de>
zeitform Internet Dienste


In reply to mod_perl: how to display the error message within the ErrorDocument by projekt21

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.