Made $session->log->fatal() message pass through
This commit is contained in:
parent
716bdaeb86
commit
42c1a8e149
6 changed files with 55 additions and 51 deletions
36
lib/WebGUI/Middleware/HTTPExceptions.pm
Normal file
36
lib/WebGUI/Middleware/HTTPExceptions.pm
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
package WebGUI::Middleware::HTTPExceptions;
|
||||
use strict;
|
||||
use parent qw(Plack::Middleware::HTTPExceptions);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
WebGUI::Middleware::HTTPExceptions - Converts Exceptions into HTTP Errors
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This is PSGI middleware for WebGUI that detects exceptions and turns
|
||||
them into HTTP Errors. This class is a subclass of L<Plack::Middleware::HTTPExceptions>
|
||||
|
||||
=cut
|
||||
|
||||
use Carp ();
|
||||
use Try::Tiny;
|
||||
use Scalar::Util 'blessed';
|
||||
use HTTP::Status ();
|
||||
|
||||
sub transform_error {
|
||||
my $self = shift;
|
||||
my ($e, $env) = @_;
|
||||
|
||||
# Handle WebGUI::Error::Fatal errors specially, since unlike most 500
|
||||
# errors we actually want the user to see the error message (generated by
|
||||
# $session->log->fatal)
|
||||
if (blessed $e && $e->isa('WebGUI::Error::Fatal')) {
|
||||
my $message = $e->message;
|
||||
return [ 500, [ 'Content-Type' => 'text/html', 'Content-Length' => length($message) ], [ $message ] ];
|
||||
} else {
|
||||
$self->SUPER::transform_error(@_);
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
Loading…
Add table
Add a link
Reference in a new issue