Browse Source

spoon is now giving a 500-error when something went wrong

Jeroen De Meerleer 5 years ago
parent
commit
5f44094e2d
2 changed files with 30 additions and 1 deletions
  1. 26 0
      controllers/pageClass.php
  2. 4 1
      spoon/exception/exception.php

+ 26 - 0
controllers/pageClass.php

@@ -23,6 +23,32 @@
 	class pageClass extends controller{
 		public
 		function index() {
+			$protocol = ($_SERVER['SERVER_PORT']  == 443) ? 'https://' : 'http://';
+			$url = $protocol.$_SERVER['HTTP_HOST'].'/api/getBugfix';
+
+			$headers = get_headers($url, 1);
+			
+			
+			if (!stripos($headers[0], '200') > 0) {
+				http_response_code(500);
+				echo '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
+<html><head>
+<title>500 Internal Server Error</title>
+</head><body>
+<h1>Internal Server Error</h1>
+<p>The server encountered an internal error or
+misconfiguration and was unable to complete
+your request.</p>
+<p>Please contact the server administrator at 
+ me@jeroened.be to inform them of the time this error occurred,
+ and the actions you performed just before this error.</p>
+<p>More information about this error may be available
+in the server error log.</p>
+</body></html>
+';
+				exit;
+			}
+			
 			$model = new page();
 			$model->apiCall[]["call"] = "getBugFix";
 			$this->create_template("index.tpl", $model);

+ 4 - 1
spoon/exception/exception.php

@@ -54,7 +54,10 @@ class SpoonException extends Exception
 	{
 		// parent constructor
 		parent::__construct((string) $message, (int) $code);
-
+		
+		// Set statusCode
+		http_response_code(500);
+		
 		// set name
 		$this->name = get_class($this);