From 60a46234290b6f41339327b4dd15285a2dd2e1fb Mon Sep 17 00:00:00 2001 From: Ben XO <75862+ben-xo@users.noreply.github.com> Date: Mon, 17 Oct 2022 18:49:02 +0100 Subject: [PATCH] Update errors to be more helpful when accessing valid paths that are empty, as opposed to invalid paths --- dir2cast.php | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/dir2cast.php b/dir2cast.php index 0629a9a..535440e 100644 --- a/dir2cast.php +++ b/dir2cast.php @@ -1195,7 +1195,10 @@ protected function scan() self::$DEBUG && print("$item_count items added.\n"); if(self::$EMPTY_PODCAST_IS_ERROR && 0 == $item_count) - throw new Exception("No Items found in {$this->source_dir}"); + { + http_response_code(404); + throw new Exception("No content yet."); + } $this->calculateItemHash(); @@ -1580,12 +1583,20 @@ public static function display($message, $errfile, $errline) { if(self::$errors) { - if(!defined('CLI_ONLY') && !ini_get('html_errors')) + if(!defined('CLI_ONLY') || !CLI_ONLY) + { + if(!http_response_code()) + { + http_response_code(500); + }q + } + + if((!defined('CLI_ONLY') || !CLI_ONLY) && !ini_get('html_errors')) { header("Content-type: text/plain"); // reset the content-type } - if(!defined('CLI_ONLY') && ini_get('html_errors')) + if((!defined('CLI_ONLY') || !CLI_ONLY ) && ini_get('html_errors')) { header("Content-type: text/html"); // reset the content-type @@ -1605,14 +1616,16 @@ public static function display($message, $errfile, $errline)
@@ -1631,15 +1644,15 @@ public static function display($message, $errfile, $errline) echo strip_tags(self::get_primed_error(ErrorHandler::$primer)) . "\n"; } - throw new ExitException("", -1); + exit(-1); // can't throw - this is the exception handler } } public static function display404($message) { - if(defined('CLI_ONLY')) + if(defined('CLI_ONLY') && CLI_ONLY) { - header("HTTP/1.0 404 Not Found"); + http_response_code(404); header("Content-type: text/plain"); } throw new ExitException("Not Found: $message", -2);