Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Made $session->log->fatal() message pass through
- Loading branch information
Showing
6 changed files
with
55 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters