refactored page() to catch some more errors.
This commit is contained in:
parent
435020c550
commit
3cb1a6619c
1 changed files with 30 additions and 18 deletions
|
|
@ -123,9 +123,11 @@ sub page {
|
||||||
my $assetUrl = shift;
|
my $assetUrl = shift;
|
||||||
my $output = processOperations();
|
my $output = processOperations();
|
||||||
if ($output eq "") {
|
if ($output eq "") {
|
||||||
my $asset = WebGUI::Asset->newByUrl($assetUrl,$session{form}{revision});
|
my $asset = eval{WebGUI::Asset->newByUrl($assetUrl,$session{form}{revision})};
|
||||||
|
if ($@) {
|
||||||
|
WebGUI::ErrorHandler::warn("Couldn't instantiate asset for url: ".$session{wguri}." Root cause: ".$@);
|
||||||
|
}
|
||||||
if (defined $asset) {
|
if (defined $asset) {
|
||||||
$session{asset} = $asset;
|
|
||||||
my $method = "view";
|
my $method = "view";
|
||||||
if (exists $session{form}{func}) {
|
if (exists $session{form}{func}) {
|
||||||
$method = $session{form}{func};
|
$method = $session{form}{func};
|
||||||
|
|
@ -134,21 +136,17 @@ sub page {
|
||||||
$method = "view";
|
$method = "view";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$method = "www_".$method;
|
$output = tryAssetMethod($asset,$method);
|
||||||
$output = eval{$asset->$method()};
|
}
|
||||||
if ($@) {
|
}
|
||||||
WebGUI::ErrorHandler::warn("Couldn't call method ".$method." on asset for ".$session{wguri}." Root cause: ".$@);
|
if ($output eq "") {
|
||||||
$output = $asset->www_view;
|
WebGUI::HTTP::setStatus("404","Page Not Found");
|
||||||
} else {
|
my $notFound = WebGUI::Asset->getNotFound;
|
||||||
if ($output eq "" && $method ne "view") {
|
if (defined $notFound) {
|
||||||
$output = $asset->www_view;
|
$output = tryAssetMethod($notFound,'view');
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
my $notFound = WebGUI::Asset->getNotFound;
|
WebGUI::ErrorHandler::warn("The notFound page failed to be created!");
|
||||||
WebGUI::HTTP::setStatus("404","Page Not Found");
|
$output = "An error was encountered while processing your request.";
|
||||||
$session{asset} = $notFound;
|
|
||||||
$output = $notFound->www_view;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $output;
|
return $output;
|
||||||
|
|
@ -187,12 +185,26 @@ sub setup {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
sub tryAssetMethod {
|
||||||
|
my $asset = shift;
|
||||||
|
my $method = shift;
|
||||||
|
$session{asset} = $asset;
|
||||||
|
my $methodToTry = "www_".$method;
|
||||||
|
my $output = eval{$asset->$methodToTry()};
|
||||||
|
if ($@) {
|
||||||
|
WebGUI::ErrorHandler::warn("Couldn't call method ".$method." on asset for url: ".$session{wguri}." Root cause: ".$@);
|
||||||
|
$output = tryAssetMethod($asset,'view') if ($method ne "view");
|
||||||
|
}
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
sub uploadsHandler {
|
sub uploadsHandler {
|
||||||
my $r = shift;
|
my $r = shift;
|
||||||
my $s = Apache2::ServerUtil->server;
|
my $s = Apache2::ServerUtil->server;
|
||||||
my $ok = Apache2::Const::OK();
|
my $ok = Apache2::Const::OK;
|
||||||
my $notfound = Apache2::Const::NOT_FOUND();
|
my $notfound = Apache2::Const::NOT_FOUND;
|
||||||
if (-e $r->filename) {
|
if (-e $r->filename) {
|
||||||
my $path = $r->filename;
|
my $path = $r->filename;
|
||||||
$path =~ s/^(\/.*\/).*$/$1/;
|
$path =~ s/^(\/.*\/).*$/$1/;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue