This commit is contained in:
Marcin Kurczewski 2014-02-05 08:32:19 +01:00
parent 6a407fc87a
commit b22e74c0e9
9 changed files with 17 additions and 10 deletions

View file

@ -42,6 +42,7 @@ class Bootstrap
if (empty($this->context->route))
{
http_response_code(404);
$this->context->viewName = 'error-404';
$this->render();
return;
@ -59,6 +60,8 @@ class Bootstrap
}
catch (SimpleException $e)
{
if ($e instanceof SimpleNotFoundException)
http_response_code(404);
StatusHelper::failure(rtrim($e->getMessage(), '.') . '.');
if (!$this->context->handleExceptions)
$this->context->viewName = 'message';

View file

@ -55,7 +55,7 @@ class LogController
$name = str_replace(['/', '\\'], '', $name); //paranoia mode
$path = TextHelper::absolutePath($this->config->main->logsPath . DS . $name);
if (!file_exists($path))
throw new SimpleException('Specified log doesn\'t exist');
throw new SimpleNotFoundException('Specified log doesn\'t exist');
//load lines
$lines = file_get_contents($path);

View file

@ -497,7 +497,7 @@ class PostController
$path = TextHelper::absolutePath($this->config->main->filesPath . DS . $post->name);
if (!file_exists($path))
throw new SimpleException('Post file does not exist');
throw new SimpleNotFoundException('Post file does not exist');
if (!is_readable($path))
throw new SimpleException('Post file is not readable');

View file

@ -31,7 +31,7 @@ abstract class AbstractCrudModel implements IModel
return self::convertRow($row);
if ($throw)
throw new SimpleException('Invalid ' . static::getTableName() . ' ID "' . $key . '"');
throw new SimpleNotFoundException('Invalid ' . static::getTableName() . ' ID "' . $key . '"');
return null;
}

View file

@ -146,7 +146,7 @@ class PostModel extends AbstractCrudModel
return self::convertRow($row);
if ($throw)
throw new SimpleException('Invalid post name "' . $key . '"');
throw new SimpleNotFoundException('Invalid post name "' . $key . '"');
return null;
}
@ -171,7 +171,7 @@ class PostModel extends AbstractCrudModel
return self::convertRow($row);
if ($throw)
throw new SimpleException('Invalid post hash "' . $hash . '"');
throw new SimpleNotFoundException('Invalid post hash "' . $hash . '"');
return null;
}

View file

@ -126,7 +126,7 @@ class TagModel extends AbstractCrudModel
return self::convertRow($row);
if ($throw)
throw new SimpleException('Invalid tag name "' . $key . '"');
throw new SimpleNotFoundException('Invalid tag name "' . $key . '"');
return null;
}

View file

@ -35,7 +35,7 @@ implements IModel
public static function findByToken($key, $throw = true)
{
if (empty($key))
throw new SimpleException('Invalid security token');
throw new SimpleNotFoundException('Invalid security token');
$query = (new SqlQuery)
->select('*')
@ -47,7 +47,7 @@ implements IModel
return self::convertRow($row);
if ($throw)
throw new SimpleException('No user with such security token');
throw new SimpleNotFoundException('No user with such security token');
return null;
}

View file

@ -95,7 +95,7 @@ class UserModel extends AbstractCrudModel
return self::convertRow($row);
if ($throw)
throw new SimpleException('Invalid user name "' . $key . '"');
throw new SimpleNotFoundException('Invalid user name "' . $key . '"');
return null;
}
@ -112,7 +112,7 @@ class UserModel extends AbstractCrudModel
return self::convertRow($row);
if ($throw)
throw new SimpleException('Invalid user name "' . $key . '"');
throw new SimpleNotFoundException('Invalid user name "' . $key . '"');
return null;
}

View file

@ -0,0 +1,4 @@
<?php
class SimpleNotFoundException extends SimpleException
{
}