1Plack::Middleware::HTTPUEsxecrepCtoinotnrsi(b3u)ted PerlPlDaoccku:m:eMnitdadtlieownare::HTTPExceptions(3)
2
3
4

NAME

6       Plack::Middleware::HTTPExceptions - Catch HTTP exceptions
7

SYNOPSIS

9         use HTTP::Exception;
10
11         my $app = sub {
12             # ...
13             HTTP::Exception::500->throw;
14         };
15
16         builder {
17             enable "HTTPExceptions", rethrow => 1;
18             $app;
19         };
20

DESCRIPTION

22       Plack::Middleware::HTTPExceptions is a PSGI middleware component to
23       catch exceptions from applications that can be translated into HTTP
24       status codes.
25
26       Your application is supposed to throw an object that implements a
27       "code" method which returns the HTTP status code, such as 501 or 404.
28       This middleware catches them and creates a valid response out of the
29       code. If the "code" method returns a code that is not an HTTP redirect
30       or error code (3xx, 4xx, or 5xx), the exception will be rethrown.
31
32       The exception object may also implement "as_string" or overload
33       stringification to represent the text of the error. The text defaults
34       to the status message of the error code, such as Service Unavailable
35       for 503.
36
37       Finally, the exception object may implement "as_psgi", and the result
38       of this will be returned directly as the PSGI response.
39
40       If the code is in the 3xx range and the exception implements the
41       'location' method (HTTP::Exception::3xx does), the Location header will
42       be set in the response, so you can do redirects this way.
43
44       There are CPAN modules HTTP::Exception and HTTP::Throwable, and they
45       are perfect to throw from your application to let this middleware catch
46       and display, but you can also implement your own exception class to
47       throw.
48
49       If the thrown exception is not an object that implements either a
50       "code" or an "as_psgi" method, a 500 error will be returned.
51       Alternatively, you can pass a true value for the "rethrow" parameter
52       for this middleware, and the exception will instead be rethrown. This
53       is enabled by default when "PLACK_ENV" is set to "development", so that
54       the StackTrace middleware can catch it instead.
55

AUTHOR

57       Tatsuhiko Miyagawa
58

SEE ALSO

60       paste.httpexceptions HTTP::Exception HTTP::Throwable
61
62
63
64perl v5.12.3                      2011-06-2P2lack::Middleware::HTTPExceptions(3)
Impressum