default error pages

31 views
Skip to first unread message

Jonathan Swartz

unread,
May 18, 2012, 9:27:01 AM5/18/12
to psgi-...@googlegroups.com
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). 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.

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?

Thanks
Jon

Tatsuhiko Miyagawa

unread,
May 18, 2012, 11:48:39 AM5/18/12
to psgi-...@googlegroups.com
On Friday, May 18, 2012 at 6:27 AM, 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).

Unlike Apache, Plack is not a document server - it's totally up to the PSGI application what kind of content it serves up, even including the error cases. There's no "configuration" per se for this.
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.

I'm puzzled what you really mean by "pages". If you use Catalyst, Dancer or Mojolicious with Plack, when you hit a URL that doesn't match/exist, you'll see error pages generated by the framework.

Also, if you *really* use a document server such as Plack::App::File/Directory, you'll see a minimum error page like "404 Not Found" if you hit a page that doesn't exist. 
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?

Thanks
Jon

--
Tatsuhiko Miyagawa

Jakob Voss

unread,
May 18, 2012, 12:01:31 PM5/18/12
to psgi-...@googlegroups.com
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

Jonathan Swartz

unread,
May 18, 2012, 6:53:27 PM5/18/12
to psgi-...@googlegroups.com
On May 18, 2012, at 8:48 AM, Tatsuhiko Miyagawa wrote:

On Friday, May 18, 2012 at 6:27 AM, 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).

Unlike Apache, Plack is not a document server - it's totally up to the PSGI application what kind of content it serves up, even including the error cases. There's no "configuration" per se for this.
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.

I'm puzzled what you really mean by "pages". If you use Catalyst, Dancer or Mojolicious with Plack, when you hit a URL that doesn't match/exist, you'll see error pages generated by the framework.

Also, if you *really* use a document server such as Plack::App::File/Directory, you'll see a minimum error page like "404 Not Found" if you hit a page that doesn't exist. 

Fair enough. I'm still working out what does and does not belong in Plack.

Plack::Middleware::StackTrace is enabled in dev mode, so there's at least *some* justification for thinking that certain kinds of error messages would be auto-generated.

Anyway, as the creator of a framework (Poet) I guess it is up to me to generate these error pages. :)

Thanks
Jon

Reply all
Reply to author
Forward
0 new messages