404 properly when post is not found

This commit is contained in:
Alex Grintsvayg 2016-08-18 14:01:45 -04:00
parent d05fd00f73
commit 300b5192e4
2 changed files with 8 additions and 3 deletions

View file

@ -85,8 +85,11 @@ class ContentActions extends Actions
public static function executeNewsPost($relativeUri)
{
$post = Post::load(ltrim($relativeUri, '/'));
if (!$post)
try
{
$post = Post::load(ltrim($relativeUri, '/'));
}
catch (PostNotFoundException $e)
{
return ['page/404', []];
}

View file

@ -1,5 +1,7 @@
<?php
class PostNotFoundException extends Exception {}
class Post
{
const SORT_DATE_DESC = 'sort_date_desc';
@ -33,7 +35,7 @@ class Post
return static::load($slugMap[$slug]);
}
}
throw new InvalidArgumentException('No post found for path: ' . $relativeOrAbsolutePath);
throw new PostNotFoundException('No post found for path: ' . $relativeOrAbsolutePath);
}
list($ignored, $frontMatter, $content) = explode('---', file_get_contents($path), 3);