perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andreas Mock" <>
Subject RE: Mod Perl - Custom Error Pages
Date Tue, 25 Oct 2011 16:35:42 GMT
Hi David,

there is;#100379

thanks to Torsten.

And here is a snippet, I use

    elsif($response->status == Apache2::Const::HTTP_NOT_FOUND) {
        # Cookies trotzdem mitschicken
        foreach my $cookie ($response->headers->header('Set-Cookie')) {
            $r->err_headers_out->add('Set-Cookie' => $cookie);
        if($response->body()) {
            $r->subprocess_env('suppress-error-charset' => 1);
            $r->err_headers_out->add('Content-Type' => $response->content_type());
            $r->custom_response(Apache2::Const::HTTP_NOT_FOUND, $response->body());
        return Apache2::Const::OK;

It's just for example, but you should get the point. $response is an object I return
from the functions doing the stuff. It encapsulates several aspects. I'm pretty
sure you can read that. $r is the well known mod_perl-object.

There is an issue with older IE-Browser which present the own message if the
message given to an error status is too short. You have to google for that.
As far as I can remember the solution is to extend the string. But I never bothered
about crappy browsers in error handling.

The line >>> if($response->body()) { <<< is interesting as it triggers
the printing of
your own message or - when not given - the error mechanism described by
Torsten. So you can have default error pages, e.g. nicely formatted pages for
customers saying something meaningful like 'A error has occurred'. Or you can
feed informations for certain cornercases or debugging.

Hope I could help. Greetings to Torsten.

Best regards
Andreas Mock

> -----Original Message-----
> From: David Hofmann []
> Sent: Tuesday, October 25, 2011 5:20 PM
> To:
> Subject: Mod Perl - Custom Error Pages
> For a while now my system has error trapped issues the it encounters
> and printed an error page with a 200 status code.
> Recently when my web developer started using AJAX, this became a
> problem, be cause he couldn't check for error codes on the pages. So I
> updated my error routine to pass proper error code like:
> print "Content-type: text/html\n";
> print "Status: 400 Bad Request", "\n\n";
> The problem I am however encountering is my custom error page
> generated by the perl script is displayed and then bellow it on the
> same page is the error page defined in the apache conf for that code.
> The reason I want the mod perl to generate the error page is I want to
> be able to pass error info in the html comments.
> Is there a way to tell get mod perl to tell apache to not send the
> default page also?
> David

View raw message