[Maypole] catching DB errors

Simon Flack sf@flacks.net
Wed, 26 Jan 2005 13:25:20 +0000


Toby Corkindale wrote:
[snip]
>>>Have you read teh Maypole::Manual::Request error handling section?  I follow
>>>that model, then when i come to an error just do a "return $r->error("Error.
>>>we're dead")"  .
>>
>>I've read it, but it's not really clear how the error () routine it suggests
>>is supposed to behave wrt fatal exceptions etc?
>>
>>I'll experiment some more.
>>Thanks for the tip.
> 
> 
> (Replying to myself; first sign of madness?)
> 
> However, I've tried putting an error subroutine into both the main driver
> class, and also the model classes too.
> In neither case was it actually called when the DB threw up an error.

The 404 response you're getting intrigues me.

Assuming your DB throws an error whilst processing a model action, 
Maypole will call invoke an 'exception' method in your model class (if 
such a method exists), or it will call $r->exception() if it doesn't.

The default $r->exception just returns Maypole::Constants::ERROR and you 
should end up with the error sent to STDERR. If you have enabled 
$r->debug, Maypole should also output the error and return ERROR to the 
handler. I'm not sure how Apache translates that into a 404. It's also 
possible that something else entirely is happening.

If you want to deal with fatal errors differently, you can define your 
own $r->exception() or add model-specific 'exception' handlers to each 
of your model classes.

HTH
Simon