Discussion:
[Mason-devel] Cluebat needed for working with the error handling
Ask Bjørn Hansen
2010-09-13 09:30:47 UTC
Permalink
Somewhat related to the index.html post:

In my project that's now running on Plack/PSGI[1] I need to handle 404's more gracefully than they are by default. By default the 404s show up just as server errors.

Under apache the request handler uses _handle_error() to rethrow

sub _handle_error
{
my ($self, $err) = @_;

if (isa_mason_exception($err, 'TopLevelNotFound')) {
rethrow_exception $err;
...

... and I'm guessing this somehow gets turned into declining the request via the mod_perl API?

Anyway - what am I supposed to do to return something else in this case?

I'd be happy just returning a static string and flagging the request to set the status as 404; but ideally I'd like to be able to "restart" the request with a $error_404_url or run a bit of code to generate the response.

Any hints would be appreciated -- I stared at the code for almost an hour and got nowhere. It's been, ahem, a few years since I worked with Mason. :-)


- ask

[1] http://github.com/abh/HTML-Mason-PSGIHandler -- thanks to miyagawa.
--
Ask Bjørn Hansen, http://askask.com/
Dave Rolsky
2010-09-14 02:10:48 UTC
Permalink
Post by Ask Bjørn Hansen
Under apache the request handler uses _handle_error() to rethrow
sub _handle_error
{
if (isa_mason_exception($err, 'TopLevelNotFound')) {
rethrow_exception $err;
...
... and I'm guessing this somehow gets turned into declining the request via the mod_perl API?
See prepare_request for how it's handled.
Post by Ask Bjørn Hansen
Anyway - what am I supposed to do to return something else in this case?
Not sure exactly. Looking at the CGIHandler code it seems like we do
something totally different under that code ;)
Post by Ask Bjørn Hansen
Any hints would be appreciated -- I stared at the code for almost an
hour and got nowhere. It's been, ahem, a few years since I worked with
Mason. :-)
I think you want wrap $interp->exec in an eval and handle the errors
yourself.


-dave

/*============================================================
http://VegGuide.org http://blog.urth.org
Your guide to all that's veg House Absolute(ly Pointless)
============================================================*/

Loading...