Tests for methods that die. Strange tom-foolery to get $@ into the logged message...
This commit is contained in:
parent
3a9a3dd8e9
commit
8a448e8f96
2 changed files with 17 additions and 11 deletions
|
|
@ -572,11 +572,6 @@ the output from the www_view method.
|
|||
|
||||
Any leftover part of the requested URL.
|
||||
|
||||
=head3 _view
|
||||
|
||||
This option should only be used internally, when trying to call the view method when
|
||||
the requested method has failed.
|
||||
|
||||
=cut
|
||||
|
||||
sub dispatch {
|
||||
|
|
@ -597,12 +592,11 @@ sub dispatch {
|
|||
my $output = eval { $self->$sub(); };
|
||||
if (my $e = Exception::Class->caught('WebGUI::Error::ObjectNotFound::Template')) {
|
||||
#WebGUI::Error::ObjectNotFound::Template
|
||||
warn "logged an exception";
|
||||
$session->log->error(sprintf "%s templateId: %s assetId: %s", $e->error, $e->templateId, $e->assetId);
|
||||
}
|
||||
elsif ($@) {
|
||||
warn "logged a warn: $@";
|
||||
$session->log->warn("Couldn't call method www_".$func." on asset for url: ".$session->url->getRequestedUrl." Root cause: ".$@);
|
||||
my $message = $@;
|
||||
$session->log->warn("Couldn't call method www_".$func." on asset for url: ".$session->url->getRequestedUrl." Root cause: ".$message);
|
||||
}
|
||||
return $output if $output || $viewing;
|
||||
##No output, try the view method instead
|
||||
|
|
@ -611,7 +605,9 @@ sub dispatch {
|
|||
$session->log->error(sprintf "%s templateId: %s assetId: %s", $e->error, $e->templateId, $e->assetId);
|
||||
}
|
||||
elsif ($@) {
|
||||
$session->errorHandler->warn("Couldn't call method www_".$func." on asset for url: ".$session->url->getRequestedUrl." Root cause: ".$@);
|
||||
warn "logged another warn: $@";
|
||||
my $message = $@;
|
||||
$session->log->warn("Couldn't call method www_view on asset for url: ".$session->url->getRequestedUrl." Root cause: ".$@);
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,6 +66,11 @@ sub www_brokenTemplate {
|
|||
);
|
||||
}
|
||||
|
||||
sub www_dies {
|
||||
my $self = shift;
|
||||
die "...aside from that bullet\n";
|
||||
}
|
||||
|
||||
package main;
|
||||
|
||||
my $tag = WebGUI::VersionTag->getWorking( $session );
|
||||
|
|
@ -74,7 +79,7 @@ WebGUI::Test->addToCleanup( $tag );
|
|||
#----------------------------------------------------------------------------
|
||||
# Tests
|
||||
|
||||
plan tests => 16; # Increment this number for each test you create
|
||||
plan tests => 18; # Increment this number for each test you create
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Test dispatch
|
||||
|
|
@ -136,7 +141,12 @@ $session->request->setup_body( {
|
|||
} );
|
||||
WebGUI::Test->interceptLogging;
|
||||
is( $td->dispatch, "www_view", "if a query method throws a Template exception, view is returned instead" );
|
||||
is $WebGUI::Test::logger_error, 'Template not found templateId: This is a GUID assetId: '. $td->getId, 'logged an error';
|
||||
is $WebGUI::Test::logger_error, 'Template not found templateId: This is a GUID assetId: '. $td->getId, '... and logged an error';
|
||||
$session->request->setup_body( {
|
||||
func => 'dies',
|
||||
} );
|
||||
is( $td->dispatch, "www_view", "if a query method dies, view is returned instead" );
|
||||
is $WebGUI::Test::logger_warns, "Couldn't call method www_dies on asset for url: Root cause: ...aside from that bullet\n", '.. and logged a warn';
|
||||
WebGUI::Test->restoreLogging;
|
||||
|
||||
#vim:ft=perl
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue