[Catalyst] Re: Serving a custom 404 page with Catalyst::Plugin::Static::Simple

Will Hawes wdhawes at gmail.com
Wed Oct 10 16:32:23 GMT 2007


On 10/10/2007, Will Hawes <wdhawes at gmail.com> wrote:
>
> With Catalyst::Plugin::Static::Simple loaded, when I request a path like
> '/static/non-existent-file', the plugin does stuff like $c->res->status(4=
04)
> for me by default. However, as I already have the following in
> MyApp::Controller::Root:
>
> sub default : Private {
>   my( $self, $c ) =3D @_;
>   $c->res->status( 404 );
>   $c->res->body( ...  );
> }
>
> I'd like to use my existing default action to display something a bit more
> user friendly when the requested static file is missing. In this case I'm
> using the test server so bypassing Catalyst::Plugin::Static::Simple
> completely is not an option.
>
> What's the correct way to implement the above?


It seems as though the answer is to comment out the following in
Catalyst::Plugin::Static::Simple (version 0.20):

$c->_debug_msg( "404: file not found: $path" )
  if $config->{debug};
$c->res->status( 404 );
$c->res->content_type( 'text/html' );

Setting a HTTP status code other than 200 causes
Catalyst::Plugin::Static::Simple::dispatch to bail out immediately, so
Catalyst::Dispatcher::dispatch never gets called for a missing static file.
Any default action in the app's root controller is ignored as a result.

Would a patch to remove the above lines (or at least make the behaviour
configurable) be welcome?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20071010/531c8=
86a/attachment.htm


More information about the Catalyst mailing list