aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdmund von der Burg <evdb@mysociety.org>2011-02-22 18:13:40 +0000
committerEdmund von der Burg <evdb@mysociety.org>2011-02-22 18:13:40 +0000
commit0f515f88ef3ca7c5711c41f8066afb689e3f5b58 (patch)
treef639b23ca9080418d230f38beb129929134baefc
parentb0ea7a45ef55e01a911121f3e2785a01bb619505 (diff)
Added templated 404 page as default
-rw-r--r--Makefile.PL1
-rw-r--r--perllib/FixMyStreet/App/Controller/Root.pm41
-rw-r--r--t/app/page_not_found.t20
-rw-r--r--templates/web/errors/page_not_found.html7
4 files changed, 47 insertions, 22 deletions
diff --git a/Makefile.PL b/Makefile.PL
index bd6667379..b16129166 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -18,6 +18,7 @@ requires 'namespace::autoclean';
requires 'Config::General';
test_requires 'Test::More' => '0.88';
+test_requires 'Test::WWW::Mechanize::Catalyst';
catalyst;
diff --git a/perllib/FixMyStreet/App/Controller/Root.pm b/perllib/FixMyStreet/App/Controller/Root.pm
index 41bca4b7f..fc3932975 100644
--- a/perllib/FixMyStreet/App/Controller/Root.pm
+++ b/perllib/FixMyStreet/App/Controller/Root.pm
@@ -4,11 +4,7 @@ use namespace::autoclean;
BEGIN { extends 'Catalyst::Controller' }
-#
-# Sets the actions in this controller to be registered with no prefix
-# so they function identically to actions created in MyApp.pm
-#
-__PACKAGE__->config(namespace => '');
+__PACKAGE__->config( namespace => '' );
=head1 NAME
@@ -26,7 +22,7 @@ The root page (/)
=cut
-sub index :Path :Args(0) {
+sub index : Path : Args(0) {
my ( $self, $c ) = @_;
# Hello World
@@ -35,38 +31,39 @@ sub index :Path :Args(0) {
=head2 default
-Standard 404 error page
+Forward to the standard 404 error page
=cut
-sub default :Path {
+sub default : Path {
my ( $self, $c ) = @_;
-
- $c->response->body( "Fallen through to FixMyStreet::App default handler" );
-
- # $c->response->body( 'Page not found' );
- # $c->response->status(404);
+ $c->detach('/page_not_found');
}
-=head2 end
+=head2 page_not_found
-Attempt to render a view, if needed.
+ $c->detach('/page_not_found');
-=cut
+Display a 404 page.
-sub end : ActionClass('RenderView') {}
+=cut
-=head1 AUTHOR
+sub page_not_found : Private {
+ my ( $self, $c ) = @_;
-Edmund von der Burg,,,
+ $c->stash->{template} = 'errors/page_not_found.html';
+ $c->response->status(404);
+}
-=head1 LICENSE
+=head2 end
-This library is free software. You can redistribute it and/or modify
-it under the same terms as Perl itself.
+Attempt to render a view, if needed.
=cut
+sub end : ActionClass('RenderView') {
+}
+
__PACKAGE__->meta->make_immutable;
1;
diff --git a/t/app/page_not_found.t b/t/app/page_not_found.t
new file mode 100644
index 000000000..9c8d7e5a6
--- /dev/null
+++ b/t/app/page_not_found.t
@@ -0,0 +1,20 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 4;
+
+use Test::WWW::Mechanize::Catalyst 'FixMyStreet::App';
+
+my $mech = Test::WWW::Mechanize::Catalyst->new;
+
+# homepage ok
+$mech->get_ok('/');
+
+# get 404 page
+my $path_to_404 = '/bad/path/page_not_found';
+my $res = $mech->get($path_to_404);
+ok !$res->is_success(), "want a bad response";
+is $res->code, 404, "got 404";
+$mech->content_contains($path_to_404);
diff --git a/templates/web/errors/page_not_found.html b/templates/web/errors/page_not_found.html
new file mode 100644
index 000000000..92ceb3106
--- /dev/null
+++ b/templates/web/errors/page_not_found.html
@@ -0,0 +1,7 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
+<html><head>
+<title>404 Not Found</title>
+</head><body>
+<h1>Not Found</h1>
+<p>The requested URL [% c.req.uri.path %] was not found on this server.</p>
+</body></html>