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, and the
51       exception is printed to the psgi.errors stream.  Alternatively, you can
52       pass a true value for the "rethrow" parameter for this middleware, and
53       the exception will instead be rethrown. This is enabled by default when
54       "PLACK_ENV" is set to "development", so that the StackTrace middleware
55       can catch it instead.
56

AUTHOR

58       Tatsuhiko Miyagawa
59

SEE ALSO

61       paste.httpexceptions HTTP::Exception HTTP::Throwable
62
63
64
65perl v5.32.0                      2020-12-0P2lack::Middleware::HTTPExceptions(3)
Impressum