You can also inherit from the HTML::Mason::ApacheHandler :

package My::MasonHandler ;

use strict ;
use HTML::Mason::ApacheHandler ;

use base qw/HTML::Mason::ApacheHandler/;

sub new{
    my ($class) = shift ;
    return $class->SUPER::new(@_);
}

sub handle_request{
    my ($self,$r) = @_;
    my $return = eval { $self->SUPER::handle_request($r) };
    if ( my $err = $@ )
    {
        $r->pnotes( error => $err );
        $r->pnotes( error_uri => $r->uri());
        $r->filename( $r->document_root . '/error/500.html' );

        return $self->SUPER::handle_request($r);
    }

    return $return;
 }
1;

And use it in lieu of HTML::Mason::ApacheHandler in your Apache conf.
(no decorated $ah required).


Jerome.


On 6 January 2011 21:22, Sherrard Burton <[email protected]> wrote:
>
> On 01/06/2011 03:29 PM, Carlson, John W. wrote:
>> Is there some way to set up mason so I get an email when there’s an
>> error thrown to the error page (and hopefully not more than one for the
>> same error).
>>
>
> can't help you with the "not more than one". but i will say that we tend
> to use the number of "repeats" to gage the magnitude, frequency,
> urgency, exposure, etc. of the problem.
>
>
> the way we did this is to:
>
> use a custom 500 error document for apache
> ErrorDocument 500 /public/error/500.html
>
> then in that file, along with the "pretty" message, we have a call to
> $m->comp( '/private/functions/send_error_email' );
>
> you can also trigger it manually to get some decent
> debugging/environmental info for stuff you're working on.
>
> form_mailer just uses Net::SMTP, or similar to send the message
>
> send_error_email:
> <%args>
>   $_type  =>  'error'
>   $_to    =>  '[email protected]'
> </%args>
> <%flags>
>   inherit => '/autohandler'
> </%flags>
> <%init>
>   %ARGS = ( %{$m->caller_args(-1)}, %ARGS );
>   my $error_text = "Page is '" . $r->uri() . "'\n\n";
>
>   # try to handle an error, if the object exists
>   if ( my $error = $r->pnotes( 'mason_error' ) ) {
>     $error_text .= UNIVERSAL::can( $error, 'as_text' ) ?
> $error->as_text : $error;
>     $error_text .= "\n\n\n";
>   } else {
>     $r->warn( "error mailing component called with no pnotes from
> '".$m->callers(1)->path()."'" );
>   }
>
>   $error_text .= "Request Method: '".$r->method()."'\n";
>   $error_text .= "The Request: '".$r->the_request()."'\n";
>   $error_text .= "URI: '".$r->uri()."'\n";
>   $error_text .= "\n\n\n";
>
>   $error_text .= "Headers\n";
>   foreach my $key ( sort keys %{$r->headers_in()} ) {
>     $error_text .= "$key: " . $r->header_in( $key ) . "\n";
>   }
>   $error_text .= "\n\n\n";
>
>   $error_text .= $m->scomp( '/scripts/dump_data_structure',
> include_html=> 0, '%ARGS' => \%ARGS );
>   $error_text .= "\n\n\n";
>
>   my %hash = (
>     from=> '[email protected]',
>     header_from=> 'Error Handler<[email protected]>',
>     to=> $_to,
>     subject=> "Mason ".ucfirst( $_type )." on $hostname ".$r->uri(),
>     body=> $error_text,
>   );
>   $m->comp( '/scripts/form_mailer', %hash );
> </%init>
> <%once>
>   my $hostname = Sys::Hostname::hostname();
> </%once>
>
>
>>
>>
>> John
>>
>>
>> ------------------------------------------------------------------------
>>
>> ------------------------------------------------------------------------------
>> Learn how Oracle Real Application Clusters (RAC) One Node allows customers
>> to consolidate database storage, standardize their database environment, and,
>> should the need arise, upgrade to a full multi-node Oracle RAC database
>> without downtime or disruption
>> http://p.sf.net/sfu/oracle-sfdevnl
>>
>>
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> Mason-users mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/mason-users
>
> ------------------------------------------------------------------------------
> Learn how Oracle Real Application Clusters (RAC) One Node allows customers
> to consolidate database storage, standardize their database environment, and,
> should the need arise, upgrade to a full multi-node Oracle RAC database
> without downtime or disruption
> http://p.sf.net/sfu/oracle-sfdevnl
> _______________________________________________
> Mason-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/mason-users
>



-- 
Jerome Eteve.

http://libsquare.net

------------------------------------------------------------------------------
Gaining the trust of online customers is vital for the success of any company
that requires sensitive data to be transmitted over the Web.   Learn how to 
best implement a security strategy that keeps consumers' information secure 
and instills the confidence they need to proceed with transactions.
http://p.sf.net/sfu/oracle-sfdevnl 
_______________________________________________
Mason-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mason-users

Reply via email to