Skip to content

Commit

Permalink
Update errors to be more helpful when accessing valid paths that are …
Browse files Browse the repository at this point in the history
…empty, as opposed to invalid paths
  • Loading branch information
ben-xo committed Oct 17, 2022
1 parent 4169eb0 commit 60a4623
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions dir2cast.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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

Expand All @@ -1605,14 +1616,16 @@ public static function display($message, $errfile, $errline)
<h1>An error occurred generating your podcast.</h1>
<div id="the_error">
<?php echo $message; ?>
<br><br>
<?php if(!empty(ErrorHandler::$primer)): ?>
<br><br>
<?php echo self::get_primed_error(ErrorHandler::$primer); ?>
<?php endif; ?>
<?php if(http_response_code() == 500): ?>
<br><br>
<div id="additional_error">
This error occurred on line <?php echo $errline; ?> of <?php echo $errfile; ?>.
</div>
<?php endif; ?>
<div id="additional_error">
This error occurred on line <?php echo $errline; ?> of <?php echo $errfile; ?>.
</div>
</div>
<div id="footer"><a href="<?php echo DIR2CAST_HOMEPAGE ?>">dir2cast</a> <?php echo VERSION; ?> by Ben XO</div>
<p>
Expand All @@ -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);
Expand Down

0 comments on commit 60a4623

Please sign in to comment.