Jonathan Swartz wrote:
> The default behavior for errors, e.g. 404 Not Found, 403 Forbidden, on
> plack servers is a blank page (unless I've got something
misconfigured).
What do you mean by plack servers? There are PSGI applications and
there are PSGI servers, but Plack is only a toolkit including some PSGI
applications and middleware. Furthermore all errors should be generated
by PSGI applications, not by any PSGI server (unless there is a bug in
the server).
> For a new development environment this seems a poor and confusing
> default, compared with say Apache's default error pages. I'm always a
> little surprised the first time I see that blank page on a new
project.
Which "new development environment" produces blank error pages? For
instance Plack::App::File produces plain test messages or if your
application
dies, there is a stack trace in the 500 error document by default.
> I see Plack::Middleware::ErrorDocument, which lets you create your own
> error pages. Is there a middleware that adds standard error pages? If
not,
> would it be legitimate for us to steal Apache's default error pages
and write
> a middleware that serves them? What would be the best way to structure
> this in relation to Plack::Middleware::ErrorDocument?
There is also an Plack::Middleware::ErrorDocument::App (not at CPAN):
https://github.com/jamadam/Plack-Middleware-ErrorDocument-App/blob/master/lib/Plack/Middleware/ErrorDocument/App.pm
I think the best is to fork the latter and add the following feature:
* support error code ranges, such as 4xx, 5xx, and 'all'
* pass the actual error code as second argument to the error app
* rename the module to Plack::Middleware::ErrorApp
Now you can implement your favorite "default error page" layout:
builder {
enable 'Plack::Middleware::ErrorApp',
4xx => sub {
my ($env, $code) = @_;
my $html = "..."; # use status_message from HTTP::Status
[ $code, "Content-Type" => "text/html", [ $html ] ];
};
$app;
};
You could also implement a set of default error pages in
Plack::Middleware::ErrorApp for convenience to allow:
enable 'Plack::Middleware::ErrorApp', all => 'plain';
enable 'Plack::Middleware::ErrorApp', all => 'html';
Each error page layout could be implemented as module that
is loaded automatically if a string is provided as app:
Plack::Middleware::ErrorApp::Plain
Plack::Middleware::ErrorApp::Html
Plack::Middleware::ErrorApp::Debug
...
Cheers,
Jakob
--
Verbundzentrale des GBV (VZG)
Digitale Bibliothek - Jakob Voᅵ
Platz der Goettinger Sieben 1
37073 Goettingen - Germany
+49 (0)551 39-10242
http://www.gbv.de
jakob...@gbv.de