aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorArne Georg Gleditsch <argggh@lxr.linpro.no>2008-02-17 23:05:18 +0100
committerArne Georg Gleditsch <argggh@lxr.linpro.no>2008-02-17 23:05:18 +0100
commit32aa8b091f439043ec2a4c7807366cb26eb9de19 (patch)
treeee64267c7a43aaf412edbf0a9bfcb9f95b871885 /lib
parentdd670fda9351186a1bf51de2a3b8192a9cda301c (diff)
Improved error handling.
Diffstat (limited to 'lib')
-rw-r--r--lib/LXRng/Context.pm2
-rw-r--r--lib/LXRng/Web.pm50
2 files changed, 46 insertions, 6 deletions
diff --git a/lib/LXRng/Context.pm b/lib/LXRng/Context.pm
index 6909c58..db486bf 100644
--- a/lib/LXRng/Context.pm
+++ b/lib/LXRng/Context.pm
@@ -82,7 +82,7 @@ sub new {
if ($$self{'tree'} and $$self{'tree'} !~ /^[+]/) {
my $tree = $$self{'tree'};
- die("No config for tree $tree")
+ return $self
unless exists($$config{$tree});
$$self{'config'} = $$config{$tree};
diff --git a/lib/LXRng/Web.pm b/lib/LXRng/Web.pm
index 78380c8..e616170 100644
--- a/lib/LXRng/Web.pm
+++ b/lib/LXRng/Web.pm
@@ -170,6 +170,28 @@ sub print_markedup_file {
}
}
+sub print_error {
+ my ($context, $template, $query, $error) = @_;
+
+ my $tmpl;
+ if ($context->config and $context->config->{'repository'}) {
+ $tmpl = 'error.tt2';
+ }
+ else {
+ $tmpl = 'bare_error.tt2';
+ }
+
+ print($query->header(-type => 'text/html',
+ -charset => 'utf-8'));
+
+ my $base = $context->base_url();
+ $template->process($tmpl,
+ {'context' => $context,
+ 'base_url' => $base,
+ 'error' => $error})
+ or die $template->error();
+}
+
sub print_tree_list {
my ($context, $template) = @_;
@@ -243,10 +265,18 @@ sub source {
my $ver = $context->release;
my $rep = $context->config->{'repository'};
- die "No tree given" unless $rep;
+ unless ($rep) {
+ print_error($context, $template, $query,
+ "No/unknown tree indicated");
+ return;
+ }
my $node = $rep->node($context->path, $ver);
- die "Node not found: ".$context->path." ($ver)" unless $node;
+ unless ($node) {
+ print_error($context, $template, $query,
+ "Node not found: ".$context->path." ($ver)");
+ return;
+ }
my $gzip = do_compress_response($query);
@@ -404,13 +434,13 @@ sub search {
my $rep = $context->config->{'repository'};
my @args = grep {
$rep->node($_, $context->release)
- } split(/\|/, $find);
+ } split(/\|/, $find);
$template_args{'ambig_res'} = {'query' => $find,
'files' => \@args,}
}
}
else {
- die "No query string given";
+ $template_args{'error'} = 'No query string given';
}
my $html = '';
$template_args{'tree'} = $context->tree;
@@ -473,6 +503,10 @@ sub handle_ajax_request {
binmode(\*STDOUT, ":gzip") if $gzip;
if ($context->param('fname') eq 'pjx_load_file') {
+ unless ($context->config and $context->config->{'repository'}) {
+ print('<div class="error">No/unknown tree indicated.</div>');
+ return;
+ }
my $rep = $context->config->{'repository'};
my $node = $rep->node($context->param('file'), $context->release);
print_markedup_file($context, $template, $node);
@@ -773,8 +807,14 @@ sub generate_pdf {
sub handle {
my ($self, $query) = @_;
- my $context = LXRng::Context->new('query' => $query);
my $template = Template->new({'INCLUDE_PATH' => $LXRng::ROOT.'/tmpl/'});
+ my $context = LXRng::Context->new('query' => $query);
+
+ unless ($context->config) {
+ print_error($context, $template, $query,
+ "No/unknown tree indicated");
+ return;
+ }
if ($context->param('fname')) {
handle_ajax_request($query, $context, $template);