Module: appdb Branch: master Commit: be04b155ec663365febc3fc2459d73f7f28f9c20 URL: http://source.winehq.org/git/appdb.git/?a=commit;h=be04b155ec663365febc3fc24...
Author: Jeremy Newman jnewman@codeweavers.com Date: Tue Nov 22 14:48:37 2016 -0600
improve item not found handling with 404 code
---
include/objectManager.php | 21 +++++++++++++++++---- objectManager.php | 15 ++++++--------- 2 files changed, 23 insertions(+), 13 deletions(-)
diff --git a/include/objectManager.php b/include/objectManager.php index 126dfac..eaf0503 100644 --- a/include/objectManager.php +++ b/include/objectManager.php @@ -181,9 +181,22 @@ class ObjectManager return $bAllowed; }
- public static function error_exit($shMessage) + public static function error_exit($shMessage, $b404 = false) { - echo '<div align="center"><p><font color="red"><b>'.$shMessage.'</b></font></p></div'; + if ($b404) + { + header("HTTP/1.1 404 Not Found"); + echo "<h1 class="whq-app-title"><i class="fa fa-exclamation-circle"></i> 404 - Not Found!</h1>\n"; + echo "<p>We are unable to find the page your are trying to access. Please check your URL and try again.</p>\n"; + } + else + { + echo "<h1 class="whq-app-title"><i class="fa fa-exclamation-circle"></i> Error!</h1>\n"; + echo "<p>We have encountered an error. More details in message below.</p>\n"; + } + echo "<p>If you feel this is an error on our end, please report it to our <a href="https://forum.winehq.org/viewforum.php?f=11%5C%22%3Eforums</a>.\n"; + echo "<hr>\n"; + echo "<p><b>Error Message:</b> {$shMessage}</p>\n"; echo apidb_footer(); exit; } @@ -1287,11 +1300,11 @@ class ObjectManager
/* Check that the entry exists */ if(!$oObject->objectGetId() && !$this->isNullIdAllowed('view')) - $this->error_exit("Entry not found (class: {$this->sClass}, id: {$this->iId})"); + $this->error_exit("Entry not found (class: {$this->sClass}, id: {$this->iId})", true);
/* Check if the entry has been deleted */ if($oObject->objectGetState() == 'deleted') - $this->error_exit("This entry has been deleted (class: {$this->sClass}, id: {$this->iId})<br>\nIts content may have been moved to another entry"); + $this->error_exit("This entry has been deleted (class: {$this->sClass}, id: {$this->iId})<br>\nIts content may have been moved to another entry", true);
/* Show a note if the entry is queued or rejected */ if($oObject->objectGetState() != 'accepted') diff --git a/objectManager.php b/objectManager.php index 37f61a9..1d3d66f 100644 --- a/objectManager.php +++ b/objectManager.php @@ -31,16 +31,13 @@ require_once(BASE.'include/tag_CommonReply.php'); require_once(BASE.'include/commonReply.php');
/* if we have no valid class name we should abort */ -if(!isset($aClean['sClass'])) +if(empty($aClean['sClass']) or !class_exists($aClean['sClass'])) { - echo "No class defined.\n"; - exit; -} - -/* make sure the class is defined */ -if(!class_exists($aClean['sClass'])) -{ - echo "Class ".$aClean['sClass']." doesn't exist"; + header("HTTP/1.1 404 Not Found"); + apidb_header("404 - Not Found!"); + echo "<h1 class="whq-app-title"><i class="fa fa-exclamation-circle"></i> 404 - Not Found!</h1>\n"; + echo "<p>We were unable to load this page due to a missing or invalid class parameter.</p>\n"; + apidb_footer(); exit; }