LP#1406025: Provide graceful human output for HTTP errors
authorDan Scott <dscott@laurentian.ca>
Sun, 28 Dec 2014 03:35:37 +0000 (22:35 -0500)
committerBen Shum <bshum@biblio.org>
Mon, 16 Feb 2015 09:29:42 +0000 (04:29 -0500)
For the expected HTTP errors of HTTP_GONE (record deleted)
and HTTP_NOT_FOUND (record never existed), return the HTML
pages that we used to return (red border warning that the
record was deleted, or just an empty template for
non-existing records) so that the user can at least try
another search. However, the HTTP status code gets set to
410 or 404 as expected so that machines can react
accordingly.

Signed-off-by: Dan Scott <dscott@laurentian.ca>
Signed-off-by: Ben Shum <bshum@biblio.org>

Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm

index d111cd2..682e2d6 100644 (file)
@@ -5,7 +5,7 @@ use XML::Simple;
 use XML::LibXML;
 use File::stat;
 use Encode;
-use Apache2::Const -compile => qw(OK DECLINED HTTP_INTERNAL_SERVER_ERROR);
+use Apache2::Const -compile => qw(OK DECLINED HTTP_INTERNAL_SERVER_ERROR HTTP_NOT_FOUND HTTP_GONE);
 use Apache2::Log;
 use OpenSRF::EX qw(:try);
 use OpenSRF::AppSession;
@@ -41,6 +41,15 @@ sub handler_guts {
 
     my $stat = run_context_loader($r, $ctx);
 
+    # Handle deleted or never existing records a little more gracefully.
+    # For these two special cases, we set the status so that the request
+    # header will contain the appropriate HTTP status code, but reset the
+    # status so that Apache will continue to process the request and provide
+    # more than just the raw HTTP error page.
+    if ($stat == Apache2::Const::HTTP_GONE || $stat == Apache2::Const::HTTP_NOT_FOUND) {
+        $r->status($stat);
+        $stat = Apache2::Const::OK;
+    }   
     return $stat unless $stat == Apache2::Const::OK;
     return Apache2::Const::DECLINED unless $template;