DocumentNotFoundException -> NotfoundException

This commit is contained in:
Tomáš Mládek 2019-11-02 14:56:05 +01:00
parent a6454c0d83
commit 81ffc6b3c5
3 changed files with 12 additions and 5 deletions

View file

@ -64,7 +64,7 @@ class PileDB
/**
* Fetch pile document as an associative array.
*
* @throws DocumentNotFoundException when document isn't found.
* @throws NotFoundException when document isn't found.
*/
public function fetchDoc($id)
{
@ -72,7 +72,7 @@ class PileDB
$stmt_doc->bindValue(":id", $id, SQLITE3_INTEGER);
$doc = $stmt_doc->execute()->fetchArray(SQLITE3_ASSOC);
if ($doc == false) {
throw new DocumentNotFoundException();
throw new NotFoundException();
}
$doc["HTMLDescription"] = $this->pd->text($doc["Description"]);
@ -201,11 +201,18 @@ class PileDB
return $stmt->execute()->fetchArray(SQLITE3_ASSOC);
}
/***
* Fetches tag as associative array.
* @throws NotFoundException
*/
public function fetchTag($tag)
{
$stmt = $this->db->prepare("SELECT * FROM Tags WHERE ID == :tag");
$stmt->bindValue(":tag", $tag, SQLITE3_INTEGER);
$tag = $stmt->execute()->fetchArray(SQLITE3_ASSOC);
if ($tag == false) {
throw new NotFoundException();
}
$tag["HTMLDescription"] = $this->pd->text($tag["Description"]);
return $tag;
}
@ -257,7 +264,7 @@ class PileDB
}
}
class DocumentNotFoundException extends Exception
class NotFoundException extends Exception
{
// noop
}

View file

@ -10,7 +10,7 @@ $page = new Template();
if (isset($_GET["item"])) {
try {
$doc = $db->fetchDoc($_GET["item"]);
} catch (DocumentNotFoundException $e) {
} catch (NotFoundException $e) {
http_response_code(404);
$page->text = "Document not found.";
$page->redirect = "/";

View file

@ -9,7 +9,7 @@ require '_util/PileDB.php';
$db = new PileDB();
try {
$doc = $db->fetchDoc($_GET["id"]);
} catch (DocumentNotFoundException $e) {
} catch (NotFoundException $e) {
http_response_code(404);
$page->text = "Document not found.";
$page->redirect = "/";