fixed: User is logged out if a fatal error occurs

error reporting and debug cleanups
This commit is contained in:
Graham Knop 2008-07-25 04:03:30 +00:00
parent e37db64483
commit 315e47781e
4 changed files with 40 additions and 34 deletions

View file

@ -1,4 +1,5 @@
7.5.18
- fixed: User is logged out if a fatal error occurs
- fixed: Collaboration system includes header link even with RSS turned off
- fixed: edit branch doesn't show list style metadata fields properly
- fixed: Product no longer shows "Continue Shopping" view when a different user adds the Product to their Cart. The issue was the Product cached itself when an item was added to the cart. Now it checks for if a cart asset exists for this session.

View file

@ -66,15 +66,14 @@ sub handler {
my $error = "";
my $matchUri = $request->uri;
my $gateway = $config->get("gateway");
$matchUri =~ s{^$gateway(.*)}{/$1};
$matchUri =~ s{^$gateway}{/};
my $gotMatch = 0;
foreach my $handler (@{$config->get("urlHandlers")}) {
WEBGUI_FATAL: foreach my $handler (@{$config->get("urlHandlers")}) {
my ($regex) = keys %{$handler};
if ($matchUri =~ m{$regex}i) {
my $output = eval { WebGUI::Pluggable::run($handler->{$regex}, "handler", [$request, $server, $config]) };
if ($@) {
$error = $@;
warn $@ if ($@ =~ "^fatal:");
last;
}
else {
@ -82,7 +81,7 @@ sub handler {
if ($output ne Apache2::Const::DECLINED) {
return $output;
}
}
}
}
}
return Apache2::Const::DECLINED if ($gotMatch);

View file

@ -19,7 +19,7 @@ use strict;
use Log::Log4perl;
use Apache2::RequestUtil;
use JSON;
use HTML::Entities;
use HTML::Entities qw(encode_entities);
=head1 NAME
@ -145,8 +145,9 @@ The message you wish to add to the log.
sub debug {
my $self = shift;
my $message = shift;
local $Log::Log4perl::caller_depth = $Log::Log4perl::caller_depth + 1;
$self->getLogger->debug($message);
$self->{_debug_debug} .= $message."\n";
$self->{_debug_debug} .= $message."\n";
}
@ -180,6 +181,7 @@ The message you wish to add to the log.
sub error {
my $self = shift;
my $message = shift;
local $Log::Log4perl::caller_depth = $Log::Log4perl::caller_depth + 1;
$self->getLogger->error($message);
$self->getLogger->debug("Stack trace for ERROR ".$message."\n".$self->getStackTrace());
$self->{_debug_error} .= $message."\n";
@ -202,6 +204,7 @@ sub fatal {
my $self = shift;
my $message = shift;
local $Log::Log4perl::caller_depth = $Log::Log4perl::caller_depth + 1;
$self->session->http->setStatus("500","Server Error");
Apache2::RequestUtil->request->content_type('text/html') if ($self->session->request);
$self->getLogger->fatal($message);
@ -228,7 +231,7 @@ sub fatal {
$self->session->output->print('<br />'.$self->session->setting->get("companyURL"),1);
}
$self->session->close();
die "fatal: " . $message;
last WEBGUI_FATAL;
}
@ -282,6 +285,7 @@ The message you wish to add to the log.
sub info {
my $self = shift;
my $message = shift;
local $Log::Log4perl::caller_depth = $Log::Log4perl::caller_depth + 1;
$self->getLogger->info($message);
$self->{_debug_info} .= $message."\n";
}
@ -301,7 +305,6 @@ An active WebGUI::Session object.
sub new {
my $class = shift;
my $session = shift;
$Log::Log4perl::caller_depth=1;
Log::Log4perl->init_once( $session->config->getWebguiRoot."/etc/log.conf" );
my $logger = Log::Log4perl->get_logger($session->config->getFilename);
bless {_queryCount=>0, _logger=>$logger, _session=>$session}, $class;
@ -326,12 +329,16 @@ sub query {
$self->{_queryCount}++;
my $plac;
if (defined $placeholders and ref $placeholders eq "ARRAY" && scalar(@{$placeholders})) {
$plac = "\n&nbsp;&nbsp;with placeholders:&nbsp;&nbsp;['".join("', '",@{$placeholders})."']";
$plac = "\n with placeholders: [" . join(', ', map {
defined $_ ? "'$_'" : 'undef';
} @$placeholders) . ']';
}
else {
$plac = '';
}
$self->debug("query ".$self->{_queryCount}.': '.$query.$plac);
local $Log::Log4perl::caller_depth = $Log::Log4perl::caller_depth + 1;
$query =~ s/^/ /gms;
$self->debug("query ".$self->{_queryCount}.":\n" . $query . $plac);
}
@ -380,31 +387,28 @@ errors, sql queries and form data.
sub showDebug {
my $self = shift;
my $text = $self->{_debug_error};
$text =~ s/\n/\<br \/\>\n/g;
my $output = '<div style="text-align: left;background-color: #800000;color: #ffffff;">'.$text."</div>\n";
my $output = '<div style="text-align: left;color: #000000; white-space: pre; float: left;">';
my $text = $self->{_debug_error};
$text = encode_entities($text);
$output .= '<div style="background-color: #800000;color: #ffffff">'.$text."</div>";
$text = $self->{_debug_warn};
$text =~ s/\n/\<br \/\>\n/g;
$output .= '<div style="text-align: left;background-color: #ffbdbd;color: #000000;">'.$text."</div>\n";
$text = encode_entities($text);
$output .= '<div style="background-color: #ffbdbd">'.$text."</div>";
$text = $self->{_debug_info};
$text =~ s/\n/\<br \/\>\n/g;
$output .= '<div style="text-align: left;background-color: #bdffbd;color: #000000;">'.$text."</div>\n";
my $form = $self->session->form->paramsHashRef();
foreach my $key (keys %{$form}) {
if ($key eq "password" || $key eq "identifier") {
$form->{$key} = "********";
}
}
$text = JSON->new->utf8->pretty->encode($form);
$text =~ s/&/&amp;/sg;
$text =~ s/>/&gt;/sg;
$text =~ s/</&lt;/sg;
$text =~ s/\n/\<br \/\>\n/g;
$text =~ s/ /&nbsp; &nbsp; /g;
$output .= '<div style="text-align: left;background-color: #aaaaee;color: #000000;">'.$text."</div>\n";
$text = encode_entities($text);
$output .= '<div style="background-color: #bdffbd">'.$text."</div>";
my %form = %{ $self->session->form->paramsHashRef };
$form{password} = "*******"
if exists $form{password};
$form{identifier} = "*******"
if exists $form{identifier};
$text = JSON->new->utf8->pretty->encode(\%form);
$text = encode_entities($text);
$output .= '<div style="background-color: #aaaaee">'.$text."</div>";
$text = $self->{_debug_debug};
$text =~ s/\n/\<br \/\>\n/g;
$output .= '<div style="text-align: left;background-color: #cccc55;color: #000000;">'.$text."</div>\n";
$text = encode_entities($text);
$output .= '<div style="background-color: #cccc55">'.$text."</div>";
$output .= '</div>';
return $output;
}
@ -425,6 +429,7 @@ The message you wish to add to the log.
sub warn {
my $self = shift;
my $message = shift;
local $Log::Log4perl::caller_depth = $Log::Log4perl::caller_depth + 1;
$self->getLogger->warn($message);
$self->{_debug_warn} .= $message."\n";
}

View file

@ -52,7 +52,7 @@ sub handler {
my ($request, $server, $config) = @_;
$request->push_handlers(PerlResponseHandler => sub {
my $session = WebGUI::Session->open($server->dir_config('WebguiRoot'), $config->getFilename, $request, $server);
foreach my $handler (@{$config->get("contentHandlers")}) {
WEBGUI_FATAL: foreach my $handler (@{$config->get("contentHandlers")}) {
my $output = eval { WebGUI::Pluggable::run($handler, "handler", [ $session ] )};
if ( my $e = WebGUI::Error->caught ) {
$session->errorHandler->error($e->package.":".$e->line." - ".$e->error);
@ -80,12 +80,13 @@ sub handler {
elsif ($session->http->getStatus < 200 || $session->http->getStatus > 299) {
$session->http->sendHeader;
last;
}
}
}
}
$session->close;
return Apache2::Const::OK;
});
$request->push_handlers(PerlMapToStorageHandler => sub { return Apache2::Const::OK });
$request->push_handlers(PerlTransHandler => sub { return Apache2::Const::OK });
return Apache2::Const::OK;
}