On Wed, 14 Jun 2006, Bryn Dyment wrote:
> If this isn't OK, what is the most straightforward Mason-friendly way to 
> close DB connection and session should things go awry?

If it works it's okay, but you could do it this way:

Always do $r->pnotes( dbh => $dbh ) when you connect.

Continue to disconnect as normal in code, because that makes sense.

In top autohandler, do:

<%init>
    use Exception::Class;
</%init>
<%perl>
    eval { $m->call_next() };
    if (my $X = Exception::Class->caught('HTML::Mason::Exception')) {
        if ( $X->isa('HTML::Mason::Exception::Abort') ) {
            my $dbh = $r->pnotes('dbh');
            $dbh->disconnect;  # good to stash sth's in there for finish() too
        }
        $X->rethrow(); # or do: warn $X; $m->redirect('/nice_error.html');
    }
</%perl>

Mark


_______________________________________________
Mason-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mason-users

Reply via email to