From: Dan Scott Date: Sun, 28 Dec 2014 03:35:37 +0000 (-0500) Subject: LP#1406025: Provide graceful human output for HTTP errors X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=40da69d80697b8f09195cac9b065ca38165b73ba;p=evergreen%2Fmasslnc.git LP#1406025: Provide graceful human output for HTTP errors 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 Signed-off-by: Ben Shum --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm index d111cd2ac9..682e2d6559 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm @@ -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;