Permalink
Browse files

Plack::Middleware::HTTPExceptions doc and test improvements

- document that uncaught exceptions are sent to psgi.errors
- ...and tests that demonstrate this feature
  • Loading branch information...
1 parent f82b691 commit 7d9771e72b04f0607b8be9097ca506644e6c47f2 @karenetheridge karenetheridge committed Jul 24, 2012
Showing with 16 additions and 1 deletion.
  1. +2 −1 lib/Plack/Middleware/HTTPExceptions.pm
  2. +14 −0 t/Plack-Middleware/httpexceptions.t
@@ -135,7 +135,8 @@ catch and display, but you can also implement your own exception class
to throw.
If the thrown exception is not an object that implements either a
-C<code> or an C<as_psgi> method, a 500 error will be returned.
+C<code> or an C<as_psgi> method, a 500 error will be returned, and the
+exception is printed to the psgi.errors stream.
Alternatively, you can pass a true value for the C<rethrow> parameter
for this middleware, and the exception will instead be rethrown. This is
enabled by default when C<PLACK_ENV> is set to C<development>, so that
@@ -26,14 +26,24 @@ sub location { "http://somewhere/else" }
package main;
+my $psgi_errors;
+
my $app = sub {
my $env = shift;
+
+ $env->{'psgi.errors'} = do { open my $io, ">>", \$psgi_errors; $io };
+
if ($env->{PATH_INFO} eq '/secret') {
HTTP::Error::Forbidden->throw;
}
if ($env->{PATH_INFO} eq '/redirect') {
HTTP::Error::Redirect->throw;
}
+
+ if ($env->{PATH_INFO} eq '/uncaught') {
+ die 'ugly stack trace here';
+ }
+
HTTP::Error::InternalServerError->throw;
};
@@ -54,6 +64,10 @@ test_psgi $app, sub {
$res = $cb->(GET '/redirect');
is $res->code, 302;
is $res->header('Location'), 'http://somewhere/else';
+
+ $res = $cb->(GET '/uncaught');
+ is $res->code, 500;
+ like $psgi_errors, qr/ugly stack trace here/;
};
done_testing;

0 comments on commit 7d9771e

Please sign in to comment.