[Midnightbsd-cvs] mports [20484] trunk/Tools/magus/www/data/magus/index.cgi: error handling - dont die, just give 404s like google expects

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Fri Oct 9 20:40:25 EDT 2015


Revision: 20484
          http://svnweb.midnightbsd.org/mports/?rev=20484
Author:   laffer1
Date:     2015-10-09 20:40:22 -0400 (Fri, 09 Oct 2015)
Log Message:
-----------
error handling - dont die, just give 404s like google expects

Modified Paths:
--------------
    trunk/Tools/magus/www/data/magus/index.cgi

Modified: trunk/Tools/magus/www/data/magus/index.cgi
===================================================================
--- trunk/Tools/magus/www/data/magus/index.cgi	2015-10-09 21:59:47 UTC (rev 20483)
+++ trunk/Tools/magus/www/data/magus/index.cgi	2015-10-10 00:40:22 UTC (rev 20484)
@@ -23,12 +23,11 @@
 while (my $p = CGI::Fast->new) {
 	eval {
   		main($p);
-		exit 0;
 	};
 
 	if ($@) {
 	  print "Content-Type: text/html\n\n";
-	  print <<END_OF_ERROR;
+      print <<END_OF_ERROR;
 	      <html>
 	      <head><title>Error</title></head>
 	      <body>
@@ -35,8 +34,7 @@
 	      <h1>Error</h1>
 	      <p>The following error occured:</p>
 	      <pre>$@</pre>
-	  END_OF_ERROR
-	  exit 0;
+END_OF_ERROR
 	}
 }
 
@@ -201,10 +199,20 @@
 }
 
 sub run_page {
-  my ($p, $run) = @_;
-  
-  $run = Magus::Run->retrieve($run) || die "No such run: $run\n";
-  
+    my ($p, $run) = @_;
+
+    eval {
+        $run = Magus::Run->retrieve($run) || die("No such run");
+    };
+    if ($@) {
+        print $p->header(
+            -type => 'text/plain',
+            -status => '404 Not Found'
+        );
+        print "404 Not Found\n";
+        exit;
+    }
+
   my $tmpl = template($p, "run.tmpl");
   $tmpl->param(title => "Run $run");
   $tmpl->param(map { $_ => $run->$_ } qw(osversion arch status created id));
@@ -312,9 +320,19 @@
 
 sub machine_page {
   my ($p, $machine) = @_;
-  
-  $machine = Magus::Machine->retrieve($machine) || die "No such machine: $machine\n";
-  
+
+    eval {
+        $machine = Magus::Machine->retrieve($machine) || die "No such machine: $machine\n";
+    };
+    if ($@) {
+        print $p->header(
+            -type=>'text/plain',
+            -status=> '404 Not Found'
+        );
+        print "404 Not Found\n";
+        exit;
+    }
+
   my $tmpl = template($p, 'machine.tmpl');
 
   (my $maint = $machine->maintainer) =~ s/\@/{...}/;
@@ -467,8 +485,18 @@
   }
   
   # $path is a category
-  my $cat = Magus::Category->retrieve(category => $path) || die "No such category: $path\n";
-  
+    eval {
+        my $cat = Magus::Category->retrieve(category => $path) || die "No such category: $path\n";
+    };
+    if ($@) {
+        print $p->header(
+            -type=>'text/plain',
+            -status=> '404 Not Found'
+        );
+        print "404 Not Found\n";
+        exit;
+    }
+
   my $tmpl = template($p, "category.tmpl");
   $tmpl->param(
     title    => "Magus // Browse // $path",
@@ -479,9 +507,6 @@
   print $p->header. $tmpl->output;
 }
 
-  
-  
-
 sub template {
   my ($p, $file) = @_;
   



More information about the Midnightbsd-cvs mailing list